Я использую MVC для разработки веб-приложения, и мне нужно использовать вложенные MasterPages на моем сайте, чтобы совместно использовать визуальные компоненты.
У меня есть две главные страницы и ContentPage:
Я хочу сослаться на ContentPlaceHolder, размещенный на верхнем Parent.master из представления содержимого который имеет Child.master как MasterPage. Кажется, что я могу использовать ContentPlaceHolders от прямого родителя, но не от косвенного родителя. Давайте посмотрим на примере:
Parent.master
<%@ Master Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage"%>
<HTML>
<head runat="server">
<title>
<asp:contentplaceholder id="Title" runat="server" />
</title>
</head>
<body>
<asp:contentplaceholder id="Body" runat="server" />
</body>
<HTML>
Child.Master
<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Parent.master"
Inherits="System.Web.Mvc.ViewMasterPage"%>
<asp:Content ID="BodyContent" ContentPlaceHolderID="Body" runat="server">
<asp:contentplaceholder id="Body1" runat="server" />
<asp:contentplaceholder id="Body2" runat="server" />
</asp:Content>
Content.aspx
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Child.master"
Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="Title" runat="server">
<!-- Placed to the top parent Master page (does not work) -->
The page title
</asp:Content>
<asp:Content ID="Body1Content" ContentPlaceHolderID="Body1" runat="server">
<!-- Placed in the direct parent Master page (Works) -->
Body content 1
</asp:Content>
<asp:Content ID="Body2Content ContentPlaceHolderID="Body2" runat="server">
<!-- Placed in the direct parent Master page (Works) -->
Body content 2
</asp:Content>
В результате я могу видеть Body content 1
и Body content 2
на моей странице, но не заголовок страницы
.