I am a beginner in Asp.Net MVC3. Can anybody please explain what is meant by this code:
@section head
{
@RenderSection("head", false)
}
On ScottGu’s article:
http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx
there is an example of RenderSection but it defines @section and then somewhere @RenderSection is used. In this case section head is defined and within that itself the same head is being rendered which confused me.
What does RenderSection do and how do I find what is being rendered here?
Scott wrote at one point
So, what RenderSection does, is rendering a section defined in the template/view (not the general _Layout).
A little bit furtherdown under “Implementing the “SideBar” Section in our View Template” he explains how to implement a section.
So all in all, what you have is a section called “head” that renders a section called “head” in a view that’s further down/nested.
Edit: have a look at http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx to see what I mean with nested views – but note that this article is over a year old now.
MasterLayout:
SubLayout:
Content: