我是使用MVC開發一個Web應用程序,並且我需要在我的網站中使用嵌套的MasterPages,以共享Visual Components。嵌套的MVC母版頁
我有兩個母版頁和ContentPage:
- Parent.master
- Child.master
- Content.aspx
我要引用放置在頂部的ContentPlaceHolder從具有Child.master作爲MasterPage的內容視圖的Parent.master。看起來我可以使用直接父代中的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
。
相關問題http://stackoverflow.com/questions/947134/are-there-nested-master-pages-in-asp-net-mvc – 2010-11-11 14:24:46