ASP. NET MVC 4 Multi-level area implementation Tips

Source: Internet
Author: User

Today at work to achieve this multilevel area. The reason is that the project needs multi-level functions, large categories have small categories, small categories have specific function items, each function item also has a number of action action, so in the menu and MVC project structure need to have a multi-level element, the menu is accordion, Every big class is a pane of accordion, and then each small class is represented by a table, and each function is represented by a cell plus a link. In the Site directory structure, area can be very convenient to achieve a level of directory structure, such as can have admin, BackOffice, logging, business reporting and other area, Each area can be a number of controllers and views, but to achieve a multilevel directory structure no one has written in detail, the author here introduces a way to achieve multilevel directory structure.

Let's say we want to implement some of the following multilevel directory structures (for example, there are only two levels, the same is true for more levels):

Admin

Access Management

Function Management

Data Permission Management

Backoffice

Risk Analysis

Risk settings

Risk reporting

Risk Transfer

Step one: Add admin and BackOffice to MVC Project two area, result 1:

The second step, here to the admin as an example, in which added Accessmanagement, functionmanagement, datapermissionmanagement several folder,2:

The third step, will controllers, Models, views, AdminAreaRegistration.cs Copy to Accessmanagement, Functionmanagement, Datapermissionmanagement directory, and then put the admin under the controllers, Models, views, AdminAreaRegistration.cs all deleted. And finally it turns out that:

Fourth step: The Accessmanagement directory in the adminarearegistration renamed to AccessManagementAreaRegistration.cs, the contents are also changed to:

Using System.web.mvc;namespace mvcapplication1.areas.admin.accessmanagement{Public    class Accessmanagementarearegistration:arearegistration    {public        override string AreaName        {            get            {                return "Admin/accessmanagement";            }        }        public override void Registerarea (AreaRegistrationContext context)        {            context. MapRoute (                "Admin_accessmanagement_default",                "Admin/accessmanagement/{controller}/{action}/{id}",                New {action = "Index", id = urlparameter.optional}            );        }    }

We need to do the same thing for Functionmanagement and Datapermissionmanagement.
So we're ready to create the controller.

If we need to create a controller for accessmanagement, right-click the Controllers directory under the "accessmanagement" directory, select Add-Controllers, Then create the view corresponding to this controller. In this way, you can create many levels of catalogs.

At the time of access, its access URL is http://

Article Source: ASP. NET MVC 4 Multi-level area implementation Tips

ASP. NET MVC 4 Multi-level area implementation Tips

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.