ASP. net mvc area operation
* 1. Create an area: Right-click and choose add> area...
* 2. inherit arearegistration and configure the route corresponding to this area
* 3. Register this area in global through arearegistration. registerallareas ();
* 4. With area, you must configure the routing namespace.
Using system. Web. MVC;
Namespace mvc20.areas. asynchronouscontroller
{
// When an area is created, the class inherited from arearegistration is automatically generated.
// If you need to use MVC in this area, you need to use arearegistration. registerallareas () in global ();
Public class asynchronouscontrollerarearegistration: arearegistration
{
Public override string areaname
{
Get
{
Return "asynchronouscontroller ";
}
}
Public override void registerarea (arearegistrationcontext context)
{
// Set the namespace (4th parameters in this example) When configuring routes in the area)
Context. maproute (
"Asynchronouscontroller_default ",
"Asynchronouscontroller/{controller}/{action}/{ID }",
New {controller = "home", Action = "Index", id = urlparameter. optional}, // parameter defaults
New String [] {"mvc20.areas. asynchronouscontroller. controllers "}
);
}
}
}
Global. asax
Code
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. MVC;
Using system. Web. Routing;
Namespace mvc20
{
Public class mvcapplication: system. Web. httpapplication
{
Public static void registerroutes (routecollection routes)
{
Routes. ignoreroute ("{resource}. axd/{* pathinfo }");
// This project uses area. Therefore, when configuring a route, you must set a namespace (4th parameters in this example)
Routes. maproute (
"Default", // route name
"{Controller}/{action}/{ID}", // URL with Parameters
New {controller = "home", Action = "Index", id = urlparameter. optional}, // urlparameter. optional-if the value of a parameter cannot be obtained from the URL route, the value of this parameter is obtained from the URL parameter.
New String [] {"mvc?controllers "}
);
}
Protected void application_start ()
{
// Register this applicationProgramAll areas in
Arearegistration. registerallareas ();
Registerroutes (routetable. routes );
}
}
}
'Mso-��-o83 �� 0.5pt; font-family: "segoe UI", "Sans-serif"; color: black; Background: # ddedfb '>False;
}
Return True;
}
}