Here we will explain to what is a Layout View in mvc .how to use layout view in mvc when we need to use layout view in mvc Create header, footer ,

Left panel by using layout view in mvc with Example.


Layout is the same as ASP.NET web form application Master page. When we need to more than one page contain common UI parts in our application such as the logo, heder, footer,Left navigation bar, right bar section in that case we should use to layout page in mvc application.

Layouts as shown in the fig.

What is Layout in mvc

Layout Code

<!DOCTYPE html>



    <meta charset="utf-8" />

    <title>@ViewBag.Title - My ASP.NET MVC Layout tutorials</title>

    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

    <meta name="viewport" content="width=device-width" />






        <div class="content-wrapper">

            <div class="float-left">

               <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p>


            <div class="float-right">                


                    <ul id="menu">

                        <li>@Html.ActionLink("Home", "Index", "Home")</li>

                        <li>@Html.ActionLink("About", "About", "Home")</li>

                        <li>@Html.ActionLink("Contact", "Contact", "Home")</li>






    <div id="body">

        @RenderSection("featured", required: false)

        <section class="content-wrapper main-content clear-fix">





        <div class="content-wrapper">

            <div class="float-left">

                <p>&copy; @DateTime.Now.Year - My ASP.NET MVC Layout tutorials</p>





    @RenderSection("scripts", required: false)



In this layout code, we are using an HTML helper method and system defined methods so let's see these methods one by one.

Url.Content(): method is a method of UrlHelper class  its specifies the path of any file that we are using in our View code. It takes the virtual path as input and returns application absolute path.

Html.ActionLink(): it is an extension method of the HtmlHelper is Used to render HTML links that links to a controller action . The first parameter takes display name, the second parameter takes the Action name and the third parameter takes the Controller name.

RenderSection(): this is a method of the WebPageBase class. "RenderSection()" helper method Specifies the name of section that we want to display at that location in the template.

RenderBody(): RenderBody() Renders the actual body of the each associated View. 


_ViewStart.cshtml set default layout page of a view.


    Layout = "~/Views/Shared/_Layout.cshtml";


Now we create home controller.

namespace MvcApplication1.Controllers


    public class HomeController : Controller


        public ActionResult Index()


            return View();




After creating home controller we add a view index.cshtml


    ViewBag.Title = "index";



Finally run application and show output.

What is Layout in mvc

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like