Posts

Showing posts from December, 2011

Understanding MVC Razor layouts

Image
Q) What are ASP.NET MVC3 Razor Layouts? You want a disclaimer, header and a menu on left to appear on all pages to bring in consistency to your web application. If you're from webforms background, you'd be quick enough to think of using a Master Page. Similar to Masterpage, MVC 3 introduces concepts of layout . Similar to selecting master page in ASPX pages in page directive, in MVC you can specify layout at global or specific view level. Q) When and how are they created? When you add a new MVC3 application (either blank or internet or intranet), Visual Studio automatically adds a default layout file called “ _layout.cshtml ” , placed in shared folder of view. Note: There is no special extension for layout file. This layout is  automatically wired in another auto generated file called “ _viewStart.cshtml ” which contains following code: @{     Layout = "~/Views/Shared/CustomLayout.cshtml"; } Of course, you can replace CustomLayout.cshtml with your custom html or alter