1. Create a new Project Testadmin project type choose one and delete it, because here I just need the solution name "project deposited in F-disk F:\TestAdmin"
2, create a new zgj. The WEB's front-page MVC project, which will start off with that casually selected item, ZGJ. Web address F:\TestAdmin\ZGJ. Web"
3, create a zgjadmin background MVC project, put in ZGJ. Web inside "Zgjadmin address F:\TestAdmin\ZGJ. Web\zgjadmin"
4. Rename the project Zgjadmin to ZGJ for aesthetics. Admin and change the assembly name and the default namespace name to Zgj in its properties. Admin
5, in Zgj. Create a new view engine under the Web customerrazorviewengine inherit from Razorviewengine
Public classCustomerrazorviewengine:razorviewengine { PublicCustomerrazorviewengine () {areaviewlocationformats=New[] { //default "~/zgjadmin/views/{1}/{0}.cshtml", "~/zgjadmin/views/shared/{0}.cshtml" }; Areamasterlocationformats=New[] { //default "~/zgjadmin/views/{1}/{0}.cshtml", "~/zgjadmin/views/shared/{0}.cshtml" }; Viewlocationformats=New[] { //default "~/views/{1}/{0}.cshtml", "~/views/shared/{0}.cshtml" }; Masterlocationformats=New[] { //default "~/views/{1}/{0}.cshtml", "~/views/shared/{0}.cshtml" }; Areapartialviewlocationformats=Areaviewlocationformats; Partialviewlocationformats=Viewlocationformats; } }
6, in Zgj. Web global.asax to load the view engine when the site is started
Public class MvcApplication:System.Web.HttpApplication { protectedvoid Application_Start () { Arearegistration.registerallareas (); Webapiconfig.register (globalconfiguration.configuration); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); ViewEngines.Engines.Clear (); VIEWENGINES.ENGINES.ADD (new customerrazorviewengine ()); } }
7, modify the ZGJ. Routeconfig in the Web adds a namespace to the default route
Public Static voidregisterroutes (routecollection routes) {routes. Ignoreroute ("{Resource}.axd/{*pathinfo}"); Routes. MapRoute (Name:"Default", URL:"{Controller}/{action}/{id}", defaults:New{controller ="Home", action ="Index", id =urlparameter.optional}, namespaces:New[] {"Zgj. Web.controllers" } ); }
8. Registration area is ZGJ. Add Class Adminarearegistration in Admin inherit from Arearegistration
Public classadminarearegistration:arearegistration { Public Override stringAreaName {Get { return "Admin"; } } Public Override voidRegisterarea (AreaRegistrationContext context) {context. MapRoute ("Admin_default", "Admin/{controller}/{action}/{id}", New{controller ="Home", action ="Index", area ="Admin", id ="" }, New[] {"Zgj. Admin.controllers" } ); } }
9, in Zgj. Add _viewstart.cshtml layout file under Admin's View directory
@{ "~/zgjadmin/views/shared/_layout.cshtml";}
10, in Zgj. Add Shared directory and add _layout.cshtml layout file under Admin's View directory
11, in Zgj. Modify the output directory of the project in the Admin's properties
MVC Site Background separation