GetReal
,而暴露的名称可以是
get-real
或
whatever
。这同样适用于控制器本身和参数。我正在寻找与 Blazor 中的路由中使用的参数完全相同的参数。
让我们考虑一下
@page "/edit/{WordId:long?}"
...
[Parameter]
public long? WordId { get; set; }
所以我的C#代号就暴露在公众面前了。我想添加我的自定义名称 - 类似于我在开头描述的 ASP.Net - 这样我就可以编写(目前不起作用):
@page "/edit/{my-custom-id:long?}"
...
[Parameter(Name = "my-custom-id")]
public long? WordId { get; set; }
有没有办法实现这个目标?
我已经提到了“路由”,而不是“查询”,但为了以防万一,澄清一下——这个问题是关于路由参数,而不是查询参数。
实现在这里:
https://github.com/dotnet/aspnetcore/blob/e1ebf00fbe63aa372051ef1c184895f169ca49f5/src/Components/Components/src/Reflection/ComponentProperties.cs#L357
并且(在使用的类型中)除了真正使用参数名称(同时不区分大小写)之外没有其他任何东西。但是控制器中的方法名称和路径不存在“暴露”原因,因为它没有在任何 uri 中进行翻译(它只是代码中段的一部分)。
@page "/edit/{this-is-not-exposed-anywhere:long}"
@attribute [Route(CustomRoutesParams.WordId)]
...
[Parameter] public long MyCustomId { get; set; }
public static class CustomRoutesParams
{
public const string WordId = "/{MyCustomId:long}";
}