MVC Series Learning (vii)-template page

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.