I want to name my ASP.NET MVC controller action as 123games
but it is not allowing me because of numeric numbers.
Do I need to use ActionNameAttribute
?
Yes, you do. The C# language specification forbids identifiers that begin with a number, as per section 2.4.2, "Identifiers":
identifier-start-character:
- letter-character
- _ (the underscore character U+005F)
Note the lack of any numeric value.
That said, you can use the ActionNameAttribute
to have a route with an action that begins with a number (because URLs have no such restriction), like so:
[ActionName("123games")]
public ActionResult _123Games()
{
// Action code.
}
Note that using an underscore is valid for the first character of an identifier (as per the same section as seen above, and specifically below, emphasis mine):
The rules for identifiers given in this section correspond exactly to those recommended by the Unicode Standard Annex 15, except that underscore is allowed as an initial character (as is traditional in the C programming language)...
So I've used that as the beginning of your method name (i.e. _123Games
) to keep it as closely aligned in your C# code as it is with the URL fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With