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: //