开发者

ASP.NET MVC Multiple Layout

开发者 https://www.devze.com 2022-12-17 02:09 出处:网络
I have a website that will contain 2 type of layout. With no columns With 2 columns Header, footer and lots of other parts are the same for both, but inside the main content, there 2 separate layo

I have a website that will contain 2 type of layout.

  1. With no columns
  2. With 2 columns

Header, footer and lots of other parts are the same for both, but inside the main content, there 2 separate layouts and I'd like to choose between 2 site masters. How would I go about accomplishing this?

I was thinking about making a main开发者_Go百科 site master and have the one with the 2 column inherit from that. If that is the correct method, what are the keywords to google for, or you are free to explain inheriting site masters here.

Thank you,


Master pages can inside a master page themselves just like any other view. Just specify the master's MasterPageFile directive as usual:

<%@ Master Language="C#" MasterPageFile="~/Views/Shared/App.Master"  
    Inherits="System.Web.Mvc.ViewMasterPage" %>

Your views can choose to use the overall master page or the nested one as their masters.

Alternately, you can set the MasterPage of your views dynamically in several ways. The regular View() method has an overload to specify the master page:

return View("SomePage", "MasterPageFileHere");

or even better would be to specify an action method to do it for you globally. You can see a good walkthrough of that here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号