Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there nested master pages in ASP.NET MVC?

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?

like image 232
OneSmartGuy Avatar asked Jun 03 '09 20:06

OneSmartGuy


People also ask

Can master pages be nested?

Master pages can be nested, with one master page referencing another as its master. Nested master pages allow you to create componentized master pages. For example, a large site might contain an overall master page that defines the look of the site.

Does MVC have master page?

Creating a View Master PageYou add a new view master page to an MVC project by right-clicking the Views\Shared folder, selecting the menu option Add, New Item, and selecting the MVC View Master Page template (see Figure 1). You can create more than one view master page in an application.

What is the difference between master page and nested master page?

The main difference between the nested master page and a content page bound to the same top-level master page is that the nested master page can include ContentPlaceHolder controls. The nested master page's ContentPlaceHolder controls define the regions where the content pages can customize the markup.

How many master page can you have?

Multiple Master Pages You can create as many masters as you want or need – for example, you want a colored box down the left margin of just some pages; you could create a master that has this look, and then apply it to only the pages that need it. 1.


1 Answers

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>
like image 182
Richard Avatar answered Oct 21 '22 09:10

Richard