Friday, December 5, 2014

using renderSection() , renderBody() and renderpage() in asp.net mvc Layouts || Masterpages in asp.net mvc

hi in this post i will show how to use renderSection() , renderBody() and renderpage() in asp.net mvc

create a empty mvc application.
1. In view folder create a Shared folder and add a new view called _Layout.cshtml. this view will act as a master page for all the pages.
1


4
in the above code i have used renderbody() which will write the contents from the other view.
for rendersection() we need to define section named RSection in the other view

2. now lets use _Layout.cshtml into our actual view named homePage.cshtml
to achieve this we need to write this below code
@{
Layout = “~/Views/Shared/_Layout.cshtml”;
}
2
in above code i have defined content for section RSection and also used renderPage() which will render view from other page named testPage.cshtml.
text hi im from homePage.cshtml will get called by renderBody() of the _Layout.cshtml.
Output:
3

No comments:

Post a Comment