The use of the region, can effectively isolate the business, a variety of business and division of labor can be more flexible. enabling zones in ASP. NET core is also very simple.
Steps to use:
1. Add a route to the zone in Startup.cs:
App. USEMVC (routes ={ routes. MapRoute (name: "area", Template: "{area:exists}/{controller=home} /{action=index}/{id?} "); Routes. MapRoute (Name:"default", Template:"{controller=home}/{action=index}/{id?}"); });
2, create the areas folder under the project, and add the corresponding Controllers, views, Models folder:
3, add HomeController.cs under Controllers, (usually I would suggest, before adding the actual controller, create Basecontroller first, and all other controllers inherit from Basecontroller, so that in the actual development process, many configurations and common methods can be more easily used, and the controller on the application of the property [Area ("name")], if set in Basecontroller. All controllers that inherit from Basecontroller do not have to repeat the settings:
[Area("Mobile")] Public class Basecontroller:controller { // GET:/<controller>/ Public iactionresult Index () { return View (); } }
4, after end multiplicity orientation, you need to add the area attribute:
Public iactionresult Test () { return redirecttoaction ("index""home") New"mobile" });
5. The front-end chain is also required to add the area attribute:
@{viewdata["Title"] =" About";}"Title"]."Message"] ThisArea to provide additional information.</p><aasp-area="mobile" Asp-controller="Home"asp-action="Index">Test</a>
OK, some other precautions to use are almost the same as the previous ASP.
Simple implementation of adding zones in ASP.