Home > Net >  MVC routing of a problem. The root directory "Admin" and "Admin" in the name of
MVC routing of a problem. The root directory "Admin" and "Admin" in the name of

Time:10-01

Root directory "Admin" controller and Areas is also the name of "admin" how to access to the root directory of the admin controller

problem is focused on, regional control product name repetition of the name and the root directory to how to solve, don't tell me change the name to oh, see what solutions

RouteConfig. Cs file content
 
Public static void RegisterRoutes (RouteCollection routes)
{
Routes. IgnoreRoute (" {resource} axd/{* pathInfo} ");

Routes. The MapRoute (
Name: "Default",
Url: "{controller}/{action}/{id}",
Defaults: new {controller="Home", action="Index", id=UrlParameter. Optional},
Namespaces: new string [] {" XXX. WEB. Controllers "}//added the other controller can access the root directory,
);
}


This is area under the routing file
AdminAreaRegistration. Cs
 
Public class AdminAreaRegistration: AreaRegistration
{
Public override string AreaName
{
The get
{
Return "Admin";
}
}

Public override void RegisterArea (AreaRegistrationContext context)
{
The context. The MapRoute (
"Admin_default,"
"Admin/{controller}/{action}/{id}",
New {action="Index", id=UrlParameter. Optional},
New string [] {XXX. WEB. Areas. Admin. "Controllers"}
);
}

CodePudding user response:

Your routing rules are not all write very clear, the root directory is/Controller/Action, Areas are in the directory/Admin/Controller/Action

CodePudding user response:

In general, as long as controller name is not the same, the name of the area and the controller with the same name is not too big

CodePudding user response:

Regional configuration

Public override void RegisterArea (AreaRegistrationContext context)
{
The context. The MapRoute (
Enclosing AreaName + "_Default,"
Enclosing AreaName + "/{controller}/{action}/{id}",
New {area=this. AreaName, controller="Home", action="Index", id=UrlParameter. Optional},
New string [] {+ "XXXXX. Web. Areas." this. AreaName + "Controllers"}
);
}
  • Related