Monday, 28 May 2018

Differences between RenderBody and RenderSection in ASP.NET MVC

In my earlier blog, I wrote about _ViewStart.cshtml file and MVC Routing.
You can read other blogs on MVC here.
In this blog, I will write about RenderBody vs RenderSection in MVC.

RenderBody() vs RenderSection()

RenderBody() -

RenderBody() must be available in Layout view i.e. it is mandatory for Layout view
RenderBody() does not take any parameter.


RenderSection() -

RenderSection() method is optional.
RenderSection() takes the parameter as section name and a boolean parameter which is optional.
The first parameter is of string type which is the name of the section i.e. In layout pages, renders the content of a named section.
The second parameter is of a boolean type which says - In layout pages, renders the content of a named section and specifies whether the section is required.

  @RenderSection("sectioname1", required: true)

Next -

No comments:

Post a Comment

Dear Readers, Please post your valuable feedback in the comment section if you like this blog or if you have any suggestions. I would love to hear the same from you. Thanks