shredding
shredding

Reputation: 131

Why doesn't controller's name has "controller" in it?

In the route config, you will have defaults: new { controller = "Home", action = "Index1", id = UrlParameter.Optional }

Here controller = "Home" instead of the defined public class HomeController : Controller. Does the compiler automatically append "Controller" at the end of Home?

Thanks!

Upvotes: 2

Views: 1117

Answers (1)

Jonathan Pantall
Jonathan Pantall

Reputation: 119

This question is answered in-depth here:

Why do MVC controllers have to have the trailing 'Controller' convention on their class name?

The short answer is that ASP.NET MVC employs the controller naming convention for standardization purposes. The compiler won't recognize a controller class unless it has a "Name" + "Controller" structure.

In contrast, when referencing a controller you can leave off the "Controller" and just call the name. It's apart of MVC framework.

Upvotes: 4

Related Questions