diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs
index c3495910a3..a58edccf8f 100644
--- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Security.Claims;
@@ -134,6 +135,25 @@ namespace Microsoft.AspNetCore.Mvc.Razor
public abstract Task ExecuteAsync();
+ ///
+ /// Format an error message about using an indexer when the tag helper property is null.
+ ///
+ /// Name of the HTML attribute associated with the indexer.
+ /// Full name of the tag helper .
+ /// Dictionary property in the tag helper.
+ /// An error message about using an indexer when the tag helper property is null.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string InvalidTagHelperIndexerAssignment(
+ string attributeName,
+ string tagHelperTypeName,
+ string propertyName)
+ {
+ return Resources.FormatRazorPage_InvalidTagHelperIndexerAssignment(
+ attributeName,
+ tagHelperTypeName,
+ propertyName);
+ }
+
///
/// Creates and activates a .
///
@@ -669,7 +689,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor
/// is called. For example, call to send
/// antiforgery cookie token and X-Frame-Options header to client before this method flushes headers out.
///
-
public virtual async Task FlushAsync()
{
// If there are active scopes, then we should throw. Cannot flush content that has the potential to change.
diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs
index 48bdfa6729..887034fb4c 100644
--- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs
@@ -32,6 +32,24 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal("Path: /PathSet.cshtml", content.Trim());
}
+ // Tests that RazorPage includes InvalidTagHelperIndexerAssignment which is called when the page has an indexer
+ // Issue https://github.com/aspnet/Mvc/issues/5920
+ [Fact]
+ public async Task TagHelper_InvalidIndexerDoesNotFail()
+ {
+ // Arrange
+ var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/TagHelpers");
+
+ // Act
+ var response = await Client.SendAsync(request);
+
+ // Assert
+ var content = await response.Content.ReadAsStringAsync();
+
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+ Assert.Equal("Post title", content.Trim());
+ }
+
[Fact]
public async Task NoPage_NotFound()
{
diff --git a/test/WebSites/RazorPagesWebSite/Show.cshtml b/test/WebSites/RazorPagesWebSite/Show.cshtml
new file mode 100644
index 0000000000..ba30ad94bb
--- /dev/null
+++ b/test/WebSites/RazorPagesWebSite/Show.cshtml
@@ -0,0 +1,5 @@
+@page
+
+@function{
+ public int Id {get; set;}
+}
diff --git a/test/WebSites/RazorPagesWebSite/TagHelpers.cshtml b/test/WebSites/RazorPagesWebSite/TagHelpers.cshtml
new file mode 100644
index 0000000000..4dcf571286
--- /dev/null
+++ b/test/WebSites/RazorPagesWebSite/TagHelpers.cshtml
@@ -0,0 +1,16 @@
+@page
+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
+
+
+
+@functions {
+ public class Post
+ {
+ public int Id { get; set; }
+ public string Title { get; set; }
+ }
+ public Post post = new Post { Id = 2, Title = "Post title" };
+}
+
+@post.Title