一起學習MVC(3)Views的學習

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   檔案   

? ??

  1. _ViewStart.cshtml、_Layout.cshtml、Index.cshtml三個頁面載入時候的先後順序就是:

    _Layout.cshtml

    ViewStart.cshtml

    Index.cshtml

    ? ??

  2. 每個View下Controller對應的檔案夾中,可以添加自己的_ViewStart.cshtml,用來指定獨自使用的布局視圖,採取就近原則(替View代根目錄中的);

    而且,_Layout架構的指派陳述式:Layout="。。。",也可以加到任意一個View檔案中,作為此檔案的單獨布局架構。

    ? ??

  3. 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>

? ??

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.