Mvc模板頁

來源:互聯網
上載者:User

標籤:控制   bundle   tar   type   his   als   --   內容   引用   

以前學過WEB的應該都知道主版頁面這個東西,在這裡呢,mvc的模板頁和WEB中的模板頁也是一樣的效果和用途。

首先:建立一個項目,控制器,產生Index視圖,在產生視圖的時候我們選擇Razor視圖引擎,然後勾選“使用布局或主版頁面”選項,它預設引用的_Layout.cshtml頁面的布局。_ViewStart.cshtml檔案裡已經對頁面進行了配置,所有的Razor引擎頁面在執行之前,都會來執行這個ViewStart頁面。

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

Layout關鍵字就是用來指向預設頁面配置的代碼。這個視圖呢就比ASPX視圖乾淨的多。

自訂布局頁:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<p>this is up</p>
@RenderBody()
<p> this is down</p>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>

在子視圖頁面中編寫的內容,都是出現在布局頁@RenderBody定義的位置。

@RenderSection布局頁面還有節(Section)的概念

當然我們的顯示還是要在視圖中編寫的

---Index:

@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>
<p>this is LayOutView</p>

 

Mvc模板頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.