views:

147

answers:

1

Possible Duplicates:
Are there nested master pages in ASP.NET MVC?
Creating nested master pages in ASP.NET Web Application

Duplicate

Are there nested master pages in ASP.NET MVC?

Can you have a master view in ASP.NET MVC that inherits from another Master View?

My reasoning is this: I have some pages that need to simply inherit from a very basic masterview that contains my header, footer and nothing else.

However, I also have a good number of pages that not only need that, but they also need border images and a container surrounding the content. Can I have a secondary master-view that inherits from the first, basic master-view?

This way I could have:

Basic Master View - Contains header, footer nothing more
Second Master View - Inherits Basic Master View as well as has its own content (some pages need)
Some views just inherit basic masterview, like our landing page
Some view inherit from secondary which should contain Basic Master view as well.

Is it possible to have multiple levels of inheritance with masterviews?

+2  A: 

MasterPages can indeed have MasterPages. Here is an MSDN article on working with "nested" Master Pages. It works pretty much the same as Pages - in the <%@ Master %> directive, just point to the MasterPageFile like you would on a Page, and put <asp:Content ... > zones.

In places on your intermediate MasterPage where you want to in turn have placeholders, insert them as you would on a top-level Master. Here is a simple example:

<%@ Master MasterPageFile="~/TopMaster.master" %>
<asp:Content runat="server" ContentPlaceholderID="LeftColumn">
    Content in the middle-level master
    <asp:ContentPlaceholder runat="server" Id="LeftColumnSubContent" />
</asp:Content>
Rex M