views:

18

answers:

1

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 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,

A: 

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.

womp