The display layer is implemented by the project and is responsible for displaying the website content. The project includes two areas: Member and Control.
The Member area implements the management of website content, and the Control area implements the management of website system. The structure and function diagrams are as follows:
1. Member area
1. Add Member area
【Right-click】->Add->Area.
Enter the area name in the Add Area dialog box that pops up: Member, and complete the area addition.
2. Add Home Controller
->Areas->Member->Controllers【Right-click】->Add->Areas.
Select MVC 5 Controller - empty and click the Add button.
Enter "HomeController" in the "Add Controller" dialog box and click the Add button. The generated code is as follows:
using System; using ; using ; using ; using ; namespace { /// <summary> /// Main controller /// </summary> public class HomeController : Controller { /// <summary> /// Main page /// </summary> /// <returns></returns> public ActionResult Index() { return View(); } } }
3. Add a view to the Index method
Right-click on the Index method -> Add View.
In the Add View dialog box, the view name: Index, template: Empty, check the Use Layout Page with the option, click the Add button to complete the view addition.
Press F5 to run the project and check it in the browserhttp://localhost:52810/Home/Index. Well, something went wrong, meaning that Home found two matching controllers.
4. Modify Member area routes
Open ->Areas->Member->
Add namespaces parameter to MapRoute. The added code is in the red box in the figure.
5. Modify the default route
Open ->App_Start->
Add a parameter with "namespaces" to MapRoute. The added code is in the red box in the figure.
Press F5 again to run it and you can see the normal page.
2. Control area
The Control area is practiced the same as the Member area.
1. Add Control area
【Right-click】->Add->Area. Enter the area name: Control in the pop-up Add Area dialog box and complete the area addition.
2. Add Home Controller
->Areas->Control->Controllers【Right-click】->Add->Areas.
Select MVC 5 Controller - empty and click the Add button.
Enter "HomeController" in the "Add Controller" dialog box and click the Add button.
3. Add a view to the Index method
Right-click -> Add View on the Index method of Home Controller.
In the Add View dialog box, the view name: Index, template: Empty, check the Use Layout Page with the option, click the Add button to complete the view addition.
4. Modify Member area routes
Open ->Areas->Control->
Add namespaces parameter to MapRoute. The added code is in the red box in the figure.
Code download: Click SOURCE CODE Click Download to download the source file.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.