开发者

Default content across nested layout

开发者 https://www.devze.com 2023-01-29 23:03 出处:网络
I have a base la开发者_如何转开发yout, BaseLayout.cshtml: <html> <body> @RenderBody()

I have a base la开发者_如何转开发yout, BaseLayout.cshtml:

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

I derive a nested layout from this, WithSidebar.cshtml:

@{ Layout = "BaseLayout.cshtml"; }

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

What changes need to be done to the WithSidebar layout:

  1. To enable the Footer section in BaseLayout to be overridden in a View?
  2. Not override the default Footer and stick with the one defined in BaseLayout?

I am developing against ASP.NET MVC 3 RC2. I have read this entry by Marcin Dobosz: http://blogs.msdn.com/b/marcinon/archive/2010/12/08/optional-razor-sections-with-default-content.aspx but I don't it works cleanly across nested layouts.


My original technique requires some extra functionality. I've written a new post that solves the issue:


To override a section:

@section Footer {
    <div>Put your overriden content here</div>
}
0

精彩评论

暂无评论...
验证码 换一张
取 消