Decomposition of items with areas in 15.01.29-MVC

Source: Internet
Author: User
Tags actionlink

On the MVC project, right-click New Zone (Areas) ..., the areas folder is automatically generated and a Model+controller+view MVC framework is created under the folder. In the Views folder, the Web. config is automatically generated, and the XxxAreaRegistration.cs file is automatically generated under the parent folder.

The routing rules for the current zone are automatically generated inside the TestAreaRegistration.cs. In order to avoid conflicts between this routing rule and the default routing rule in the app_start below RouteConfig.cs, it is a good idea to add the namespace parameter in two rules:

Add a line below the Application_Start () function of Global.asax: Arearegistration.registerallareas ();

protected void Application_Start () {    arearegistration.registerallareas ();    Filterconfig.registerglobalfilters (globalfilters.filters);    Routeconfig.registerroutes (routetable.routes);    Bundleconfig.registerbundles (bundletable.bundles);}

Thus, areas split management is implemented.

However, in a real-world application, the project has authentication. All of the view uses the same layout. So, the problem comes, after entering the window below the area, then click on the _layout menu above, you can see all the links into the area below, just click on the window. For example, the link to log off becomes:

At this point, we need to modify the layout file below the share file shelf.

<Divclass= "Navbar-header">    <Buttontype= "button"class= "Navbar-toggle"Data-toggle= "Collapse"Data-target= ". Navbar-collapse">        <spanclass= "Icon-bar"></span>        <spanclass= "Icon-bar"></span>        <spanclass= "Icon-bar"></span>    </Button>@Html. ActionLink ("Application Name", "Index", "Home", new {area = ""}, new {@class = "Navbar-brand" })</Div><Divclass= "Navbar-collapse collapse">    <ulclass= "Nav navbar-nav">        <Li>@Html. ActionLink ("Home", "Index", "Home",New {area = ' "}, null)</Li>        <Li>@Html. ActionLink ("About", "about", "Home",New {area = ' "}, null)</Li>        <Li>@Html. ActionLink ("Contact", "contact", "Home",New {area = ' "}, null)</Li>@if (request.isauthenticated && user.isinrole ("Admin")) {<Li>@Html. ActionLink ("Rolesadmin", "Index", "Rolesadmin",New {area = ' "}, null)</Li>            <Li>@Html. ActionLink ("Usersadmin", "Index", "Usersadmin",New {area = ' "}, null)</Li>        }    </ul>@Html. Partial ("_loginpartial")</Div>

With a red underline, the newly added RouteValue.

Decomposition of items with areas in 15.01.29-MVC

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.