SlideShare a Scribd company logo
1 of 5
Download to read offline
7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC
http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 1/5
O
Exploring Layouts, RenderBody, RenderSection and RenderPage in ASP.NET
MVC
Posted Date: 17. June 2014 Posted By: Anil Sharma
Categories: ASP.NET MVC
Keywords: Exploring Layouts, RenderBody in MVC, RenderSection in MVC, RenderPage in ASP.NET MVC, Styles.Render
and Scripts.Render in ASP.NET MVC
ne of the major requirements for our web application is to maintain a consistent look and feel across all of the
pages within your web-site/application. ASP.NET 2.0 introduced the concept of “Master Pages” which helps
enable this when using .aspx based pages or templates. To achieve this concept in ASP.NET MVC application,
Razor View Engine supports this concept with a feature called “layouts”- which allow us to define a common site
template, and then inherit its look and feel across all the views/pages on our site. Following code sample show the
basic structure of Layout.cshtml file.
This Layout.cshtml file is used to maintain a consistent look and feel in out Asp.Net MVC application, at application
level we have _ViewStart file with in Views folder for defining the default Layout page for your ASP.NET MVC
application. For rendering layout page refer this article Different ways of rendering layouts in Asp.Net MVC.
Styles.Render and Scripts.Render in ASP.NET MVC
 


1
2
3
4
5
6
7
8
9
10
11
12
13
<metacharset="utf-8">
<title>@ViewBag.Title-MyASP.NETMVCApplication</title>
<metaname="viewport"content="width=device-width">
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@RenderBody()
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts",required:false)
7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC
http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 2/5
@Style.Render is used to render a bundle of CSS files defined within BundleConfig.cs files. It(Style.Render) is
responsible to create style tag(s) for the CSS bundle. Style.Render generate multiple style tags for each items in the
CSS bundles we have when the optimizations are disabled. By enabling optimization Styles.Render generate a
single style tag to a version-stamped URL which represents the entire bundle for CSS.
@Scripts.Render is used to render a bundle of Script files. It(Scripts.Render) is responsible for rendering script
tag(s) for the Script bundle. Scripts.Render generate multiple script tags for each items in the Scripts bundles we
have when the optimizations are disabled. By enabling optimization Scripts.Render generate a single scripts tag to a
version-stamped URL which represents the entire bundle for Scripts. Following is the sample BundleConfig.cs file's
code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
publicclassBundleConfig
{
//FormoreinformationonBundling,visithttp://go.microsoft.com/fwlink/?LinkId=254725
publicstaticvoidRegisterBundles(BundleCollectionbundles)
{
bundles.Add(newScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"
bundles.Add(newScriptBundle("~/bundles/jqueryui").Include("~/Scripts/jquery-ui-{version}
bundles.Add(newScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive
"~/Scripts/jquery.validate*"));
//UsethedevelopmentversionofModernizrtodevelopwithandlearnfrom.Then,whenyo
//readyforproduction,usethebuildtoolathttp://modernizr.comtopickonlythetest
bundles.Add(newScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*"));
bundles.Add(newStyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(newStyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC
http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 3/5
You can enable and disable optimizations by setting EnableOptimizations property of BundleTable class to true or
false with in Global.asax.cs file as shown below.
RenderSection in ASP.NET MVC
Layout pages also have the concept of sections. A layout page can only contain one RenderBody method, but can
have multiple sections. To create a section you use the RenderSection method. The difference between
RenderSection and RenderPage is RenderPage reads the content from a file; whereas RenderSection runs code
blocks you define in your content pages. The following code sample shows how to use RenderSection in ASP.NET
MVC. A view can define only those sections that are referred to in the layout page otherwise an exception will be
thrown.
We can render above defined section header on the content page, following code sample shows how it can be
done.
In ASP.NET MVC by default, sections are mandatory. To make sections optional, just add the second parameter,
which is a Boolean value. Following code block shows that:
RenderBody in ASP.NET MVC
30
31
32
33
}
1
2
3
4
5
protectedvoidApplication_Start()
{
//OtherLogic
System.Web.Optimization.BundleTable.EnableOptimizations=false;
}
1
2
3
@sectionheader{
<h1>HeaderContent</h1>
}
1 @RenderSection("header")
1 @RenderSection("header",false)
7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC
http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 4/5
RenderBody method exists in the Layout page to render child page/view. It is just like the ContentPlaceHolder in
master page. A layout page can only be one RenderBody method per layout page. The RenderBody method
indicates where view templates that are based on this master layout file should “fill in” the body content. Following
code block shows how to use RenderBody in ASP.NET MVC.
RenderPage in ASP.NET MVC
RenderPage method also exists in the Layout page to render other page exists in your application. A layout page
can have multiple RenderPage method. This is achieved by using the RenderPage method. This method takes
either one or two parameters. The first is the physical location of the file, the second is an optional array of objects
that can be passed into the page.
Summary:This article covers the Layouts, RenderBody, RenderSection and RenderPage in ASP.NET MVC. I hope
this will be useful for you. I will suggest you to go through another article to understand different ways of rendering
layouts in Asp.Net MVC.
Keen to here from you...!
If you have any questions related to what's mentioned in the article or need help with any issue, ask it, I would love to
here from you. Please MakeUseOf Contact and i will be more than happy to help.
1 @RenderBody()
1 @RenderPage("~/Views/Shared/_LoginPartial.cshtml")
7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC
http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 5/5
About the author
Anil Sharma is Chief Editor of dotnet-stuff.com. He's a software professional
and loves to work with Microsoft .Net. He's usually writes articles about .Net
related technologies and here to shares his experiences, personal notes,
Tutorials, Examples, Problems & Solutions, Code Snippets, Reference
Manual and Resources with C#, Asp.Net, Linq , Ajax, MVC, Entity
Framework, WCF, SQL Server, jQuery, Visual Studio and much more...!!!
Connect with the author: • Google + • Linkedin

More Related Content

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC

  • 1. 7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 1/5 O Exploring Layouts, RenderBody, RenderSection and RenderPage in ASP.NET MVC Posted Date: 17. June 2014 Posted By: Anil Sharma Categories: ASP.NET MVC Keywords: Exploring Layouts, RenderBody in MVC, RenderSection in MVC, RenderPage in ASP.NET MVC, Styles.Render and Scripts.Render in ASP.NET MVC ne of the major requirements for our web application is to maintain a consistent look and feel across all of the pages within your web-site/application. ASP.NET 2.0 introduced the concept of “Master Pages” which helps enable this when using .aspx based pages or templates. To achieve this concept in ASP.NET MVC application, Razor View Engine supports this concept with a feature called “layouts”- which allow us to define a common site template, and then inherit its look and feel across all the views/pages on our site. Following code sample show the basic structure of Layout.cshtml file. This Layout.cshtml file is used to maintain a consistent look and feel in out Asp.Net MVC application, at application level we have _ViewStart file with in Views folder for defining the default Layout page for your ASP.NET MVC application. For rendering layout page refer this article Different ways of rendering layouts in Asp.Net MVC. Styles.Render and Scripts.Render in ASP.NET MVC     1 2 3 4 5 6 7 8 9 10 11 12 13 <metacharset="utf-8"> <title>@ViewBag.Title-MyASP.NETMVCApplication</title> <metaname="viewport"content="width=device-width"> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") @RenderBody() @Scripts.Render("~/bundles/jquery") @RenderSection("scripts",required:false)
  • 2. 7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 2/5 @Style.Render is used to render a bundle of CSS files defined within BundleConfig.cs files. It(Style.Render) is responsible to create style tag(s) for the CSS bundle. Style.Render generate multiple style tags for each items in the CSS bundles we have when the optimizations are disabled. By enabling optimization Styles.Render generate a single style tag to a version-stamped URL which represents the entire bundle for CSS. @Scripts.Render is used to render a bundle of Script files. It(Scripts.Render) is responsible for rendering script tag(s) for the Script bundle. Scripts.Render generate multiple script tags for each items in the Scripts bundles we have when the optimizations are disabled. By enabling optimization Scripts.Render generate a single scripts tag to a version-stamped URL which represents the entire bundle for Scripts. Following is the sample BundleConfig.cs file's code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 publicclassBundleConfig { //FormoreinformationonBundling,visithttp://go.microsoft.com/fwlink/?LinkId=254725 publicstaticvoidRegisterBundles(BundleCollectionbundles) { bundles.Add(newScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js" bundles.Add(newScriptBundle("~/bundles/jqueryui").Include("~/Scripts/jquery-ui-{version} bundles.Add(newScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive "~/Scripts/jquery.validate*")); //UsethedevelopmentversionofModernizrtodevelopwithandlearnfrom.Then,whenyo //readyforproduction,usethebuildtoolathttp://modernizr.comtopickonlythetest bundles.Add(newScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*")); bundles.Add(newStyleBundle("~/Content/css").Include("~/Content/site.css")); bundles.Add(newStyleBundle("~/Content/themes/base/css").Include( "~/Content/themes/base/jquery.ui.core.css", "~/Content/themes/base/jquery.ui.resizable.css", "~/Content/themes/base/jquery.ui.selectable.css", "~/Content/themes/base/jquery.ui.accordion.css", "~/Content/themes/base/jquery.ui.autocomplete.css", "~/Content/themes/base/jquery.ui.button.css", "~/Content/themes/base/jquery.ui.dialog.css", "~/Content/themes/base/jquery.ui.slider.css", "~/Content/themes/base/jquery.ui.tabs.css", "~/Content/themes/base/jquery.ui.datepicker.css", "~/Content/themes/base/jquery.ui.progressbar.css", "~/Content/themes/base/jquery.ui.theme.css")); }
  • 3. 7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 3/5 You can enable and disable optimizations by setting EnableOptimizations property of BundleTable class to true or false with in Global.asax.cs file as shown below. RenderSection in ASP.NET MVC Layout pages also have the concept of sections. A layout page can only contain one RenderBody method, but can have multiple sections. To create a section you use the RenderSection method. The difference between RenderSection and RenderPage is RenderPage reads the content from a file; whereas RenderSection runs code blocks you define in your content pages. The following code sample shows how to use RenderSection in ASP.NET MVC. A view can define only those sections that are referred to in the layout page otherwise an exception will be thrown. We can render above defined section header on the content page, following code sample shows how it can be done. In ASP.NET MVC by default, sections are mandatory. To make sections optional, just add the second parameter, which is a Boolean value. Following code block shows that: RenderBody in ASP.NET MVC 30 31 32 33 } 1 2 3 4 5 protectedvoidApplication_Start() { //OtherLogic System.Web.Optimization.BundleTable.EnableOptimizations=false; } 1 2 3 @sectionheader{ <h1>HeaderContent</h1> } 1 @RenderSection("header") 1 @RenderSection("header",false)
  • 4. 7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 4/5 RenderBody method exists in the Layout page to render child page/view. It is just like the ContentPlaceHolder in master page. A layout page can only be one RenderBody method per layout page. The RenderBody method indicates where view templates that are based on this master layout file should “fill in” the body content. Following code block shows how to use RenderBody in ASP.NET MVC. RenderPage in ASP.NET MVC RenderPage method also exists in the Layout page to render other page exists in your application. A layout page can have multiple RenderPage method. This is achieved by using the RenderPage method. This method takes either one or two parameters. The first is the physical location of the file, the second is an optional array of objects that can be passed into the page. Summary:This article covers the Layouts, RenderBody, RenderSection and RenderPage in ASP.NET MVC. I hope this will be useful for you. I will suggest you to go through another article to understand different ways of rendering layouts in Asp.Net MVC. Keen to here from you...! If you have any questions related to what's mentioned in the article or need help with any issue, ask it, I would love to here from you. Please MakeUseOf Contact and i will be more than happy to help. 1 @RenderBody() 1 @RenderPage("~/Views/Shared/_LoginPartial.cshtml")
  • 5. 7/16/2014 Exploring Layouts, RenderBody, RenderSection and RenderPage in .NET MVC http://www.dotnet-stuff.com/tutorials/aspnet-mvc/exploring-layouts-renderbody-rendersection-and-renderpage-in-asp-net-mvc 5/5 About the author Anil Sharma is Chief Editor of dotnet-stuff.com. He's a software professional and loves to work with Microsoft .Net. He's usually writes articles about .Net related technologies and here to shares his experiences, personal notes, Tutorials, Examples, Problems & Solutions, Code Snippets, Reference Manual and Resources with C#, Asp.Net, Linq , Ajax, MVC, Entity Framework, WCF, SQL Server, jQuery, Visual Studio and much more...!!! Connect with the author: • Google + • Linkedin