Tuesday, 18 February 2014

RenderSection method in MVC3

You define the section in a view and render it in _Layout.cshtml. Section can contain any code that you normally put in a view, i.e. HTML, CSS or JavaScript or a combination of them.

RenderSection can only exist in Layout files i.e. master pages. If you want make a section that is reusable on many pages then you should go for a partial view.

Defining a section
@section Footer{
<p>This message is for Footer.</p>
}
Referencing a section
@RenderSection("Footer",false)
The second parameter is a boolean and specifies whether it is a required section or not.

Try below urls for more information

Layouts and sections with razor

RenderBody, RenderPage and RenderSection methods in MVC

No comments:

Post a Comment