Simple implementation of adding zones in ASP.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.