Add InvalidTagHelperIndexerAssignment to RazorPageBase
This commit is contained in:
parent
e44d875df4
commit
365ae19c8b
|
|
@ -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();
|
||||
|
||||
/// <summary>
|
||||
/// Format an error message about using an indexer when the tag helper property is <c>null</c>.
|
||||
/// </summary>
|
||||
/// <param name="attributeName">Name of the HTML attribute associated with the indexer.</param>
|
||||
/// <param name="tagHelperTypeName">Full name of the tag helper <see cref="Type"/>.</param>
|
||||
/// <param name="propertyName">Dictionary property in the tag helper.</param>
|
||||
/// <returns>An error message about using an indexer when the tag helper property is <c>null</c>.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public string InvalidTagHelperIndexerAssignment(
|
||||
string attributeName,
|
||||
string tagHelperTypeName,
|
||||
string propertyName)
|
||||
{
|
||||
return Resources.FormatRazorPage_InvalidTagHelperIndexerAssignment(
|
||||
attributeName,
|
||||
tagHelperTypeName,
|
||||
propertyName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and activates a <see cref="ITagHelper"/>.
|
||||
/// </summary>
|
||||
|
|
@ -669,7 +689,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
/// <see cref="FlushAsync"/> is called. For example, call <see cref="SetAntiforgeryCookieAndHeader"/> to send
|
||||
/// antiforgery cookie token and X-Frame-Options header to client before this method flushes headers out.
|
||||
/// </remarks>
|
||||
|
||||
public virtual async Task<HtmlString> FlushAsync()
|
||||
{
|
||||
// If there are active scopes, then we should throw. Cannot flush content that has the potential to change.
|
||||
|
|
|
|||
|
|
@ -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("<a href=\"/Show?id=2\">Post title</a>", content.Trim());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NoPage_NotFound()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
@page
|
||||
|
||||
@function{
|
||||
public int Id {get; set;}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
@page
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
<!-- Tests that RazorPage includes InvalidTagHelperIndexerAssignment which is called when the page has an indexer
|
||||
Issue https://github.com/aspnet/Mvc/issues/5920 -->
|
||||
|
||||
@functions {
|
||||
public class Post
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
public Post post = new Post { Id = 2, Title = "Post title" };
|
||||
}
|
||||
|
||||
<a asp-route-page="/Show" asp-route-id="@post.Id">@post.Title</a>
|
||||
Loading…
Reference in New Issue