Styles.Render(""),調用CSS。<link href="" rel="stylesheet"/>,需在BundleConfig.cs中進行設定。
Scripts.Render(""),調用JS。<script src=""></script>,需在BundleConfig.cs中進行設定。
@RenderBody(),用於佔位,調用主顯示頁面。如在路由類裡設定了Home,Index.則在此處調用index.cshtml
@Html.Partial("_Navigation"),調用分布視圖,如導航頁等。可用於配合AJAX的局部重新整理
@RenderSection("scripts", required: false),佔位節點。如為false,則為不是必須。可進行佔位顯示。
一個Layout可以包含多個分塊(setions),例如,可以為Layout添加Footer分塊
? ??
<footer>@RenderSection("Footer")</footer>
? ??
在使用這個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>