Homenamespace webapplication8.areas.weather.controllers{public class Homecontroller:controller established under Area { //get:weather/home public actionresult Index () { return Content GetType (). FullName);}}} Homenamespace webapplication8.controllers{public class Homecontroller:controller created under the Controller file { //Get:home public actionresult Index () { return Content GetType (). FullName);}}}
Run-time prompt:
According to the error we all know what is the reason, how to modify it, there are two ways, perhaps we all know is a kind of through the RouteTable.Routes.MapRoute method, to carry out namespaces constraints, such as:
public static void RegisterRoutes (RouteCollection routes) { routes. Ignoreroute ("{resource}.axd/{*pathinfo}"); Routes. MapRoute ( name: "Default", URL: "{controller}/{action}/{id}", defaults:new {controller = "Home", action = "Index", id = urlparameter.optional}, constraints:null, namespaces:new string[] {" WebApplication8.Areas.Weather.Controllers "} );
By running, sure enough to recognize the right;
Just now there's another way to change that priority.
In the controller, there is the Controllerbuilder class that is responsible for registering the controller, through which he can register, and elevate the priority
Such as:
protected void Application_Start () { ControllerBuilder.Current.DefaultNamespaces.Add (" Webapplication8.controllers "); Arearegistration.registerallareas (); Routeconfig.registerroutes (routetable.routes); }
Results:
,
But who has a higher priority, and I'm going to run chrome with both methods, and know that the Maproute registered by routing is higher priority.
How to increase controller priority in MVC5.0