Are there nested master pages in ASP.NET MVC?
Asked Answered
H

2

14

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?

Honewort answered 3/6, 2009 at 20:45 Comment(0)
N
10

Yep. I just saw a blog post about this at: http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/

Very cool stuff.

Narcose answered 3/6, 2009 at 20:49 Comment(2)
You beat me to it. Good post.Hodge
Looks like I just needed to catch up on my tweets. elijahmanor: "ASP.NET MVC and the templated partial view (death to ASCX)" by @jeffreypalermo #tech #aspnetmvc bit.ly/ctKii" Thanks!Honewort
N
40

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>
Notice answered 3/6, 2009 at 20:55 Comment(2)
Nice example, I like how you demonstrate that you can use the same ContentPlaceHolder ID at each level of master template.Monafo
@Richard: Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" is giving error in my case. Rather I used Inherits="System.Web.Mvc.ViewMasterPage" and it worked well. Could you please explain why is it? But indeed your answer is excellent.Converter
N
10

Yep. I just saw a blog post about this at: http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/

Very cool stuff.

Narcose answered 3/6, 2009 at 20:49 Comment(2)
You beat me to it. Good post.Hodge
Looks like I just needed to catch up on my tweets. elijahmanor: "ASP.NET MVC and the templated partial view (death to ASCX)" by @jeffreypalermo #tech #aspnetmvc bit.ly/ctKii" Thanks!Honewort

© 2022 - 2024 — McMap. All rights reserved.