嵌套布局中的默认内容

时间:2010-12-12 11:31:22

标签: asp.net-mvc asp.net-mvc-3 layout razor

我有一个基本布局,BaseLayout.cshtml:

<html>
<body>
    @RenderBody()
    <div id="footer">
        @if (!IsSectionDefined("Footer")) {
            Default footer markup
        }
        else {
            @RenderSection("Footer")
        }
    </div>
</body>
</html>

我从中导出了一个嵌套布局,WithSidebar.cshtml:

@{ Layout = "BaseLayout.cshtml"; }

<div>
    <div>
        @RenderBody()
    </div>
    <div>Sidebar</div>
</div>

需要对WithSidebar布局进行哪些更改:

  1. 要在BaseLayout中启用Footer部分,以便在View?
  2. 中重写
  3. 不覆盖默认的页脚并坚持使用BaseLayout中定义的页脚?
  4. 我正在针对ASP.NET MVC 3 RC2进行开发。我已经阅读了Marcin Dobosz的这篇文章:http://blogs.msdn.com/b/marcinon/archive/2010/12/08/optional-razor-sections-with-default-content.aspx但我不能在嵌套布局中干净利落地工作。

2 个答案:

答案 0 :(得分:2)

我的原创技术需要一些额外的功能。我写了new post解决了这个问题:

答案 1 :(得分:0)

覆盖部分:

@section Footer {
    <div>Put your overriden content here</div>
}
相关问题