zoukankan      html  css  js  c++  java
  • @RenderSection

    @RenderSection在母版页中先占个位置,然后在使用该母版的页面中在各自去实现自己的Section。

    在母版页_Layout.cshtml中使用格式为

    @RenderSection("Section名") 或者 @RenderSection("Section名", false)

    没有加false,默认为true,表示加载了母版页的页面必须实现Section,否则产生异常。

    加上false,表示加载了母版页的页面可以实现Section,也可以不实现。

    例,在_Layout.cshtml中有

    <body>

        @RenderSection("Menu")

    </body>

    在一个使用了_Layout.cshtml作母版的Index.cshtml中就要定义名字为Menu的Section:

    @section Menu{
        Hello This is a section implement in Index View.
    }

    另外,如果希望当所有子页都没有实现这个Section的时候,母版页可以有自己的呈现内容,就可以用 

    <div id="sideBar">
    @if (IsSectionDefined("Menu"))
    {
        @RenderSection("Menu", false)
    }
    else
    {
        <p>Menu Section is not defined!</p>
    }
    </div>
    这样当没有任何页面呈现Section的时候,就会默认显示定义的内容。

  • 相关阅读:
    bzoj4974: [Lydsy1708月赛]字符串大师
    bzoj1801: [Ahoi2009]chess 中国象棋
    predis的使用
    常用的文件数据类型mime
    使用CURL模拟表单上传文件
    模型类:连接数据库
    extends注意事项
    extends前提
    include
    radio后的input框数据传递
  • 原文地址:https://www.cnblogs.com/brown-birds/p/4065327.html
Copyright © 2011-2022 走看看