Asp.net mvc 4 Multi-Level area implementation skills

Source: Internet
Author: User

At work today, we need to implement this multi-level area. The reason is that this project requires multi-level functions. There are small categories in large categories, specific functional items in small categories, and each functional item has several Action actions, therefore, the structure of menus and mvc projects must contain multi-level elements. Menus use accordion, and each category is a pane of accordion, then each small class is represented by a table, and each function is represented by a cell and a link. In the website directory structure, area can easily implement a level-1 directory structure, such as admin, backoffice, logging, and business reporting, there can be several controllers and views in each area, but no one has written them in detail to implement a multi-level directory structure. Here I will introduce a method to implement a multi-level directory structure.

Suppose we want to implement the following multi-level directory structure (Here we only use two levels for example, the principle of more levels is the same ):

Admin

Access Management

Function Management

Data Permission Management

Backoffice

Risk analysis

Risk settings

Risk reporting

Risk transfer

Step 1: Add Admin and Backoffice to the MVC project. Result 1:

Step 2, here we will take Admin as an example, add AccessManagement, FunctionManagement, DataPermissionManagement to several Folder, 2:

Step 3: Copy Controllers, Models, Views, and AdminAreaRegistration. cs to the AccessManagement, FunctionManagement, DataPermissionManagement directories, and delete all Controllers, Models, Views, and AdminAreaRegistration. cs under Admin. The final result is as follows:

Step 4: Rename AdminAreaRegistration in the AccessManagement directory to AccessManagementAreaRegistration. cs, and change the content:

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 for FunctionManagement and DataPermissionManagement.
In this way, we are ready to create a controller.

If you need to create a controller for AccessManagement, right-click the Controllers directory under the "AccessManagement" directory, select Add-> Controllers, and then create the View corresponding to this controller. In this way, you can create multiple levels of directories.

During access, the access URL is http: //

 

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.