A RenderSection allow to specify a region of content within a layout. It expects one parameter which is the name of the section. If we do not provide that, an exception will be thrown. A section in a layout page can be defined by using the following code.
@section header { <h1>Header Content</h1> }
we can render above defined section header on the content page as given below:
@RenderSection("header")
By default, sections are mandatory. To make sections optional, just provides the second parameter value as false, which is a Boolean value.
@RenderSection("header",false)
A view can define only those sections that are referred to in the layout page otherwise an exception will be thrown.
RenderBody:
RenderBody method exists in the Layout page to render child page/view. It is just like the ContentPlaceHolder in master page. A layout page can have only one RenderBody method.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
@RenderSection("header")@RenderSection("header",false)