Display ASP.NET MVC action parameter name to another name

Can I associate an action parameter with a different name?

I want to use reserved words as parameters for an action, for example:

search?q=someQuery&in=location&for=x

The in and for values ​​cannot be used as method parameter names. Is there a built-in function for this, or should I create a model binding?

Thanks.

+3
source share
1 answer

You can use the @ notation to interpret a name literally, rather than a reserved word in C #.

public ActionResult Test(string @for)
{
    var something = @for;
}
+11
source

Source: https://habr.com/ru/post/1713597/


All Articles