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