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:
- To enable the Footer section in BaseLayout to be overridden in a View?
- 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>
}
精彩评论