ASP. NET MVC Area operations
- New Area: Right-click add–> area
- Inherit Arearegistration, override AreaName property and Registerarea method
Public classbookstudyarearegistration: arearegistration{ Public Override string areaname {Get { return "Bookstudy"; } } Public Override void Registerarea(AreaRegistrationContext context) {context. MapRoute ("Bookstudy_default",
"bookstudy/{controller}/{action}/{id}" , New " Index ", id = urlparameter.optional} );} }
- (Attached: generic route map)
public class public Static void registerroutes (RouteCollection routes) {routes. Ignoreroute ( " {resource }.axd/{*pathinfo} " ); Routes. MapRoute (name: " defaul T " url:
" {controller}/{action}/{id} " , New " Home " " Index ", id = urlparameter.optional}, newstring" Mykb.controllers" } );} }
Please note that withRegisterareaThe URL parameter to compare, only a "bookstudy", that is, areaname. -This is also called the areaSub-stationThe reason.
- Register this area in Global
protected void Application_Start () { arearegistration.registerallareas (); // Here filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); Bundleconfig.registerbundles (bundletable.bundles);}
- All of the above steps are automatically generated in VS2013 or VS2012.