I want to have some default content for a section let suppose Footer. How can I do this.
Also, what if I want to render a partial view as the default content.
Thanks
@section is for defining a content are override from a shared view. Basically, it is a way for you to adjust your shared view (similar to a Master Page in Web Forms).
The @section directive is used in conjunction with MVC and Razor Pages layouts to enable views or pages to render content in different parts of the HTML page.
RenderBody() is called to render the content of a child view. Any content on said view that is not in a @section declaration will be rendered by RenderBody() . Using the Layout view above, that means that all content in a child view will be rendered inside the <div class="container body-content"> .
@RenderSection("nameOfSection", required: false)
@if (!IsSectionDefined("nameOfSection"))
{
<div>Default section content</div>
}
Haacked blogged about this http://haacked.com/archive/2011/03/05/defining-default-content-for-a-razor-layout-section.aspx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With