1. Create a new MVC project and select the basic
2. View Files
See vs generates Something for us
Layout page, layout specifies the template page
3. Start an instance
First the code in the controller is as follows:
The code in the view is as follows:
1. In/views/_viewstart.cshtml "If/views has the child view under it, the runtime first loads it first then it has a higher priority than the other views" 2. On the/views/shared/_layout.cshtml "template page or Layout page, if Layout=null is not set in the view, the layout page is called by default" 3. In the/views/home/_viewstart.cshtml "after loading/views _viewstart.cshtml, It then iterates through the folder under the current request view for a view with the name _viewstart.cshtml, and then loads " 4. "View of this study" in/views/home/sonpage.cshtml |
After running, the browser shows the results as follows
The source code is "HTML tag is still very clean":
Come to the conclusion
1. When the Sonpage.cshtml view page is requested, 2. First, the compiler will load a view named _viewstar.cshtml into the View folder (takes precedence over all views and can have one in any folder) 3. If the layout property in _viewstart.cshtml is not NULL, which means that the layouts page is loaded, the layout page is loaded according to the value of layout, 3.1 In the layout page, you can specify different page locations to render different page content 4. Then, under the folder where the view (sonpage.cshtml) is located, see if there is a file named _viewstar.cshtml, and then load it, 5. Finally, the view of this request is loaded (sonpage.cshtml) 6. Find the template page in the "small pit", then the template page pits in the appropriate place to fill the pit (if it is necessary to fill, you can not fill in), and then sonpage.cshtml in the other content, are filled in the big pits |
MVC Series Learning (vii)-template page