Is the controller name derived from the class name?

This is a newbie question ...

I am looking at the asp.net mvc3 project by default and noticed that there is a controller:

public class AccountController : Controller

I looked through all the code and could not find the place where the AccountController data is specified in / Account / for the URL.

I found that you can change the routing using routes.MapRoute(..)in Global.asax, but I still don't know where they indicated that the AccountController maps to / Account /.

If this is assumed from the class name, does this mean that all controller classes should be named xxxxxController?

+5
source share
3 answers

, , "Controller".

. ControllerName ASP.NET MVC CodePlex:

public virtual string ControllerName {
    get {
        string typeName = ControllerType.Name;
        if (typeName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))
        {
            return typeName.Substring(0, typeName.Length - "Controller".Length);
        }
        return typeName;
    }
}

, , factory.

, .

+6

, MVC- CoC, . , , , , , .., , , . , , , , .

MVC . , XxxxController, , View\Xxxx\Yyyyy.cshtml.

+6

Yes, if you do not implement your own factory controller.

0
source

All Articles