2

I tried to create a Controller class with the name 1BigController, but MVC won't let me do that. It changes the controller name to _BigController.

Why can't I start a controller name with a number?

1
  • Please, tag questions relating to ASP.NET with tag "asp.net", ".net" etc. Thanks. Commented Feb 25, 2011 at 16:43

4 Answers 4

5

This is a convention of all C# classes, not just MVC. You can find more in the C# Language Specification (item 2.4.2)

Here's a similar question regarding variable names and numeric vals

Why can't variable names start with numbers?

Sign up to request clarification or add additional context in comments.

Comments

1

It could be because you can't have class names that start with a number. I used to program PLC's and the software we used wouldn't allow us to start any tag names with a number. I don't know why we couldn't other then that was the rule.

Comments

0

MVC uses a convention approach to type resolution. A controller name such as "Big" will cause MVC to search for a BigController. Likewise, if it was not sanitised as "_" and instead was "1Big", MVC would attempt to find a type called 1BigController. Type names cannot start with numbers, so it gets sanitised for you.

Comments

0

Variable names have to start with a letter or underscore. The remaining characters can be letters, underscores, or digits. I am not sure why this is the convention, but it has been for a long time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.