The basic layout structure in MVC looks like this.
- _MyLayout.cshtml
In ASP.NET MVC, at application level we have _ViewStart file within the Views folder for defining the default layout page.- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width" />
- <title>@ViewBag.Title</title>
- @RenderSection("CSS", required: false)
- </head>
- <body>
- @RenderBody() @RenderSection("Scripts", required: false) @RenderPage("~/Views/Shared/_Demo.cshtml")
- </body>
- </html>
- BundleConfig.cs
- public class BundleConfig
- {
- public static void RegisterBundles(BundleCollection bundles)
- {
- bundles.Add(newScriptBundle("~/bundles/bootstrap")
- .Include(
- "~/Scripts/bootstrap.js", "~/Scripts/respond.js"));
- bundles.Add(newStyleBundle("~/Content/css")
- .Include("~/Content/bootstrap.css", "~/Content/site.css"));
- }
- }
- Scripts.Render generates script tags for each item in Script bundle when optimizations are disabled.
- Styles.Render generates multiple style tags in the CSS bundle.
- Index.cshtml
- @{
- ViewBag.Title = "Home";
- Layout = "~/Views/_MyLayout.cshtml";
- }
- <!-- MAIN-->
- <div id="main">
- <!-- @RenderBody()renders here.-->
- Hi , This is Demo.
- </div>
- //This section render in header part according to our _LayoutPage.cshtml.
- @section CSS {
- @Styles.Render("~/Content/css")
- <link href="~/Content/css/jquery-ui.css"rel="stylesheet"/>
- <link href="~/Content/js/rating/jquery.rateyo.css"rel="stylesheet"/>
- }
- //This section render in body part according to our _LayoutPage.cshtml.
- @section Scripts {
- @Scripts.Render("~/bundles/bootstrap ")
- <script src="~/Content/js/jquery-ui.min.js"></script>
- <script src="~/Content/js/rating/jquery.rateyo.js"></script>
- }
- @RenderPage()
RenderPage method exists in our Layout Page to render the other page if you want.
Example
- @RenderPage("~/Views/Shared/_Demo.cshtml")

Mayank SharmaPosted Jul 5, 2016, 7:40 AM
Thank you Ankur Mistry Sir !!!
Ankur MistryPosted Jul 5, 2016, 6:53 AM
Interesting article on layouts
Mayank SharmaPosted Jul 4, 2016, 1:07 AM
Thank you.
kalu singh raoPosted Jul 1, 2016, 3:28 PM
Nice...
Mayank SharmaPosted Jun 30, 2016, 7:21 AM
Thank You Mr. Abhishek !!
Abhishek AroraPosted Jun 30, 2016, 7:19 AM
Nice
Mayank SharmaPosted Jun 29, 2016, 6:59 AM
Thank You Mr. Mannan !!
Abdulmannan BahelimPosted Jun 29, 2016, 6:56 AM
Good stuf on layouts...