[MVC] View

Source: Internet
Author: User

The/views/_viewstart.cshtml file will be loaded before the other view document is loading, with the following code:

1 @{2     " ~/views/shared/_layout.cshtml " ; 3

The Logo Board page is _layout.cshtml. _viewstart.cshtml files can also appear in the Views sub-directory, the implementation of different controllers under the preset loading different main pages. _layout.cshtml Code structure:

12<div>...</div>34<div id="Body">5@RenderSection ("Featured", Required:false)6<sectionclass="content-wrapper main-content Clear-fix">7 @RenderBody ()8</section>9</div>Ten<footer> One<div>...</div> A</footer>

Note the @rendersection and @renderbody in the code, @RenderBody can be considered a "preset hole" in the Razor Main page, which means that the view is filled into the @renderbody location.

@RenderSection can be considered a "named hole" in the Razor Main page, if the required named parameter is specified as true, then all view pages loaded into the main page must output the corresponding content in @rendersection. Otherwise, an exception is generated. And "featured" is the name of the hole, because required is false, so it is not necessary to fill the named hole. The index.cshtml in the MVC template project is populated as follows:

1 @section Featured {2<sectionclass="Featured">3<divclass="Content-wrapper">4class="title">5678<p>9 To learn more about ASP. NET MVC visitTen<a href="Http://asp.net/mvc"title="ASP. NET MVC Website">http://asp.net/mvc</a>. OneThe page features <mark>videos, tutorials, and samples</mark> to help youGetThe most fromASP. NET MVC. A If you had any questions about ASP. NET MVC visit -<a href="Http://forums.asp.net/1146.aspx/1?MVC"title="ASP. NET MVC Forum">our forums</a>. -</p> the</div> -</section> -}
View Code

Razor page has a fixed order of execution, first execute view in the Execution Layout main page, because view and layout common one viewdatadictionary entity, so you can pass the data from view to layout page through ViewBag, But the reverse is not true.

[MVC] View

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.