Razor also provides another helpful method—IsSectionDefined()—which determines whether a section of a given name is defined in the content view. This information allows the layout not only to control the placement of the section’s content but also to affect other areas of the page.
in _layout page
@if(IsSectionDefined("Footer")) {
<div class="footer">
@RenderSection("Footer", required: false)
</div>
}
With this check in place, the footer div will only be rendered when the content view defines a Footer section. Otherwise, nothing will be rendered!
in _layout page
@if(IsSectionDefined("Footer")) {
<div class="footer">
@RenderSection("Footer", required: false)
</div>
}
With this check in place, the footer div will only be rendered when the content view defines a Footer section. Otherwise, nothing will be rendered!
No comments:
Post a Comment