Are there nested master pages in ASP.NET MVC?

OneSmartGuy picture OneSmartGuy · Jun 3, 2009 · Viewed 8k times · Source

I wanted to know if the MVC framework can leverage the Nested Master Page? If so does anyone have some info on how to achive this?

Answer

Richard picture Richard · Jun 3, 2009

We use nested master pages frequently, in order to seperate layout from standard includes and site wide markup, like so:

Site.Master:

<%@ Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="language" content="en">
    <title><asp:ContentPlaceHolder ID="Title" runat="server"><%= Model.Page.Title %></asp:ContentPlaceHolder></title>

    <% Html.RenderPartial("Head"); %>

    <meta name="robots" content="index, follow">
    <meta name="robots" content="noodp">
    <asp:ContentPlaceHolder ID="ExtraHead" runat="server"></asp:ContentPlaceHolder>
</head>
<body >

    <asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>

</body>
</html>

then have a another master using the Site.Master,

Standard.Master:

<%@ Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" MasterPageFile="Site.Master" %>
<asp:Content ContentPlaceHolderID="ExtraHead" runat="server">
    <asp:ContentPlaceHolder ID="ExtraHead" runat="server"></asp:ContentPlaceHolder>
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">


            <asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>


</asp:Content>