【发布时间】:2010-11-11 14:18:16
【问题描述】:
我正在使用 MVC 开发 Web 应用程序,我需要在我的站点中使用嵌套的 MasterPages,以便共享可视组件。
我有两个母版页和一个 ContentPage:
- Parent.master
- Child.master
- 内容.aspx
我想从以 Child.master 作为 MasterPage 的 Content 视图引用放置在 Parent.master 顶部的 ContentPlaceHolder。似乎我可以使用直接父级的 ContentPlaceHolders,但不能使用间接父级的 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,但看不到page title。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 master-pages contentplaceholder