_Layout.cshtml html
ViewStart.cshtml 框架
Index.cshtml 布局
并且,_Layout框架的赋值语句:Layout="。。。",也能够加到任意一个View文件中,做为此文件的单独布局框架。 ui
Scripts.Render(""),调用JS。<script src=""></script>,需在BundleConfig.cs中进行设置。 spa
@RenderBody(),用于占位,调用主显示页面。如在路由类里设置了Home,Index.则在此处调用index.cshtml htm
@Html.Partial("_Navigation"),调用分布视图,如导航页等。可用于配合AJAX的局部刷新 blog
@RenderSection("scripts", required: false),占位节点。如为false,则为不是必须。可进行占位显示。 ip
一个Layout能够包含多个分块(setions),例如,能够为Layout添加Footer分块 路由
<footer>@RenderSection("Footer")</footer> io
在使用这个Layout的View中,须要加入@section Footer{..}代码,来设置本身的footer,如:
@section Footer{ @@Copyright 2001-2015, All Right Received. }
可是,大多数时候,但愿section都是可选的,可将其改成:
<footer>@RenderSection("Footer", required: flase) </footer>
更为通用的方式,是在设置可更改的Section时,配备一个默认的Section外观:
<footer>
@if (IsSctionDefined("Footer"))
{
RenderSection("Footer");
}
else
{
<span>This is the default footer. </span>
}
</footer>