Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 22 January 2015
Keywords : Layout,Layout in MVC,What is MVC layout,Layout basics,MVC for beginner



To create a consistent look across all the pages in a web application, in ASP.NET the concept called 'master pages' is present. Consistent look can be , same header in every pages, same footer in every pages and also same style and format.
Layouts are similar to master page in asp .net mvc web forms . It provides a base template for other pages.
It allow to define a common site template, and then inherit its look and feel across all the pages on the application. It helps to maintain a constant Look and feel.

Layout pages are having two concepts that are web page body and web page section.
Web page body is just rendering the content of the referencing view at specific place. This uses the @RenderBody method to render the referencing view content at where it is placed.
Web page sections are used to declare multiple sections in a layout and these section defined by the referencing views.
_Layout.cshtml represent the layout of each page in the application and it is located in the Shared folder inside the Views folder.

To add layout : Open this file and add the required content to it.

Layout Page

Layout page contains the structure, but not the content, of a web page. When a web page is linked to a layout page, it will be displayed according to the layout page.
The layout page is like a normal web page except from a call to the @RenderBody() method where the content page will be included.

Content Page

The content page or web page start with a Layout directive.

Creation Of Layout

1. In the created MVC application, expand 'View' folder in the Solution Explorer. 'Shared' folder will be present inside it. Right click on it. A list will be appearing.

2.From that, select 'Add'. Another list will be appearing and select 'View' from that

3.The following window will be appearing. In that, give the required name for the new layout. Here given the name as '_LayoutNew' And click 'Add'.

The new layout will be created with the given name and it will be present under 'Shared' folder.

4. The newly created layout page will be open.

In the newly created layout, we can add the required code.

Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.