MVC5 website development-5 presentation layer architecture, mvc5 website development
Display layerNinesky. WebProject implementation: displays the website content. The project includesMemberAndControlTwo regions.
Member RegionTo manage website content,Control AreaImplement Website System Management. The structure and function diagram are as follows:
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. mvc; namespace Ninesky. web. areas. member. controllers {// <summary> /// master controller /// </summary> public class HomeController: controller {// <summary> /// homepage /// </summary> /// <returns> </returns> public ActionResult Index () {return View ();}}}
3.IndexMethod to add a view
InIndexRight-click the method and choose>Add View.
InAdd ViewIn the dialog box, view Name:Index, Template:Empty, SelectUse the layout page,ClickAddButton to add the view.
PressF5Run the project and check it in the browser.Http: // localhost: 52810/Home/Index. Well, an error occurred,MeaningHomeFind two matched controllers.
4. ModifyMemberRegion Routing
OpenNinesky. Web->Areas->Member->MemberAreaRegistration. cs
IsMapRouteAddNamespacesParameters. The red box in the figure shows the added code.
5. ModifyDefaultRouting
OpenNinesky. Web->App_Start->RouteConfig. Cs
IsMapRouteAddNamespacesParameters. The red box in the figure shows the added code.
PressF5Run, you can see the normal page.
II,Control Area
ControlRegional Practices andThe Member region is the same.
1. Add the Control area
Ninesky. Web [Right-click]-> Add-> area.InAdd region dialog boxEnter region name:Control,Add Region.
2. Add the Home Controller
Ninesky. Web-> Areas->Control-> Controllers [Right-click]->Add->Region.
SelectMVC 5 controller-null,ClickAddButton.
In theAdd Controller"Dialog box, enter"HomeController"ClickAddButton.
3. Add a view for the Index method
InHome ControllerOfIndexRight-click the method and choose>Add View.
InAdd ViewIn the dialog box, view Name:Index, Template:Empty, SelectUse the layout page,ClickAddButton to add the view.
4. Modify the Member region route
OpenNinesky. Web->Areas->Control->ControlAreaRegistration. cs
IsMapRouteAddNamespacesParameters. The red box in the figure shows the added code.
========================================================
See: https://ninesky.codeplex.com/SourceControl/latest for code
Code download: https://ninesky.codeplex.comClickSOURCE CODEClickDownloadDownload the source file.