I'm using ASP.NET MVC 3 with Razor views. When you want to create a view you can choose a layout (master page) for your view, or leave it to choose Default (_Layout).
I am interesting in to change this layout after create a view without recreate it, is there any where to store the layout information about the views? and how can I change it?
Creating a View Master Page You add a new view master page to an MVC project by right-clicking the Views\Shared folder, selecting the menu option Add, New Item, and selecting the MVC View Master Page template (see Figure 1). You can create more than one view master page in an application.
Q. Can we use multiple Layout pages in a single MVC application? Yes, we can use multiple Layout in ASP.Net MVC application. By default, Visual Studio adds a Layout page in a shared folder which can be used by other View pages if required.
In MVC3 you have _ViewStart.cshtml
that stores all pages' Layout; you can change this element to change all pages' Layout or you can add new Layout element in top of target view pages in @{}
block like the following to change the layout of the specific page:
@{ Layout = "~/Views/Shared/_newLayout.cshtml"; ViewBag.Title = "Index"; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With