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?
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With