Chủ Nhật, 21 tháng 9, 2014

ASP.NET MVC 4 - Layout and Section in Razor

Introduction

Suppose you are developing an ASP.NET web application and you want to maintain a consistent look and feel across all the pages within your web application. You then have two options, the first one is to design the head, body and footer sections on each page. In this approach, you need to write more code on each page so ASP.NET 2.0 introduced "Master Pages" that helps enable this when using .aspx based pages or templates. It is your second option. Razor also supports this concept with a feature called "layouts" that allow you to define a common site template, and then inherit its look and feel across all the views/pages on your web application.