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