Introduce: If you want to create multiple web pages and you want to show some common features for every pages.as like, you do not want to change header and footer section for every single page. In that case you use razor "layouts". otherwise it is very difficult, write all code for every single page.

Step 1:

  • Open Visual studio

  • Click on “File”>New>Project>Visual c#>Web> then provide your project name> then select “ok”> then click “MVC”>ok.

  • Create new controller name “RazorLayout”

  • Add two view name “Index” and “About”

Step 2:  ”1st way, select layout

  • Go to View>Shared>_Layout.cshtml

This layout show for every view.

  • @RenderBody() is required, since, it renders each view.

  • Run this project

Step 3:  ”2nd way, select layout”

  • Create new Layout name ” _Layout2”

  • Define the Layout property in the view. Like this,

  • "~/Views/Shared/_Layout2.cshtml"

Step 4:  ”3rd way, select layout”

  • Create new Layout name ” _Layout3”

  • Define the Layout property in the View Action Method. Like this,

  • ActionResult Index()

  •  View("Index","_Layout3");

Step 5 :  ”4th way, select layout”

  • You can define the Layout property, when you create a view. As like video