Tôi đang sử dụng MVC để phát triển một ứng dụng Web và tôi cần sử dụng các MasterPages lồng nhau trong trang web của mình, để chia sẻ các thành phần Visual.Các trang cái của MVC lồng nhau
Tôi có hai Master Pages và một ContentPage:
- Parent.master
- Child.master
- Content.aspx
Tôi muốn tham khảo một ContentPlaceHolder đặt lên hàng đầu Parent.master từ chế độ xem Nội dung có Child.master dưới dạng MasterPage. Có vẻ như tôi có thể sử dụng ContentPlaceHolders từ cha mẹ trực tiếp, nhưng không phải từ cha mẹ gián tiếp. Hãy xem với một mẫu:
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>
Kết quả là tôi có thể thấy Body content 1
và Body content 2
trong trang của tôi, nhưng không thể xem page title
.
Câu hỏi liên quan http://stackoverflow.com/questions/947134/are-there-nested-master-pages-in-asp-net-mvc –