Change Layout(Master Page) of view in ASP.NET MVC without recreate it

前端 未结 4 372
星月不相逢
星月不相逢 2021-01-31 08:08

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

4条回答
  •  囚心锁ツ
    2021-01-31 08:26

    After creating your view in the top of cshtml file you can see your layout included.

    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    

    You can simply replace that for example with different layout

    @{
        Layout = "~/Views/Shared/_Layout2.cshtml";
    }
    

    Also, you can store this in the base layout (_ViewStart.cshtml) and then all your views will use that layout.

提交回复
热议问题