In ASP.NET controllers for example, it is possible to create a method and at the same time provide customized, exposed name for the action. So C# method could be named GetReal, while exposed name could be get-real or whatever. Same applies for controllers themselves, and parameters.
And I am looking exactly for the same for parameters used in routes in Blazor pages.
Let's consider
@page "/edit/{WordId:long?}"
...
[Parameter]
public long? WordId { get; set; }
So my C# code name is exposed to public. I would like to add my custom name -- similarly to ASP.Net I described in the beginning -- so I could write (it does not work currently):
@page "/edit/{my-custom-id:long?}"
...
[Parameter(Name = "my-custom-id")]
public long? WordId { get; set; }
Is there a way to achieve this?
I already mentioned "route", not "query", but just in case, clarification -- this question is about route parameter, not query ones.
I don't think you can change this like you changing method names in controllers.
The implementation is here: https://github.com/dotnet/aspnetcore/blob/e1ebf00fbe63aa372051ef1c184895f169ca49f5/src/Components/Components/src/Reflection/ComponentProperties.cs#L357
And there (and in used types) is nothing other then really using the param name (while being case insensitive).
But there is not the "exposing" reason as for method names and paths in controllers, because it's not translated in any uri (it is just part of the segment in your code).
@page "/edit/{this-is-not-exposed-anywhere:long}"Also note you can do something like this to have different param name and "code" in the page attribute:
Another solution is to use the
nameofwhich will remove the need for the magic string and in case of refactoring (renaming of the param property) it remains working.