ASPDOTNETMVC : Understanding Section

In MVC, Layout Template has only one section in it- what we call the main body section of the response.
Razor also support the ability to add addition sections to layout template. we can render section by calling the 
RenderSection(string sectionname,bool required)
helper method within Layout template.

the first parameter specifies the name of the section. Second parameter is optional, and allow us to whether the section is required or not.

If section is required then it must to implement section. other wise razor will throw an error at run-time. If section is not required then it's not mandatory to implement within view template.

we could have put Section declaration anywhere within the View template.

Call Section in Layout template


Declaration of section in Index 


Detect Section conditionally

Razor provide the facility to detect section is defined or not within View Template. we can check with IsSectionDefined() method.


Tricks Always Work

Comments

Post a Comment

Popular Posts