asp.net-mvc – 嵌套的MVC母版页
发布时间:2020-12-16 03:52:35 所属栏目:asp.Net 来源:网络整理
导读:我是,使用MVC开发Web应用程序,我需要在我的站点中使用嵌套的MasterPages,以便共享Visual Components. 我有两个母版页和一个ContentPage: Parent.master Child.master Content.aspx 我想从Content视图中引用位于顶级Parent.master上的ContentPlaceHolder,该
我是,使用MVC开发Web应用程序,我需要在我的站点中使用嵌套的MasterPages,以便共享Visual Components.
我有两个母版页和一个ContentPage: > Parent.master 我想从Content视图中引用位于顶级Parent.master上的ContentPlaceHolder,该视图具有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内容1和Body内容2,但不能看到页面标题. 解决方法
内容占位符仅引用其直接父级中的内容占位符.改变你的Child.master这个:
<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Parent.master" Inherits="System.Web.Mvc.ViewMasterPage"%> <asp:Content ID="BodyContent" ContentPlaceHolderID="Body" runat="server"> <asp:Content ContentPlaceHolderID="Title" runat="server"> <asp:contentplaceholder id="TitleContent" runat="server" /> </asp:Content> <asp:contentplaceholder id="Body1" runat="server" /> <asp:contentplaceholder id="Body2" runat="server" /> </asp:Content> 因此,Child.master实际上就像Title内容占位符的“传递”一样. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 从中??等信任环境的Web.config读取system.net/m
- asp.net-mvc – ASP.NET MVC – 表单和模型绑定器中的多个模
- asp.net-core – 从Controller传递信息到中间件
- ASP.NET Core中调整HTTP请求大小的几种方法详解
- 代码“Request.Headers.Range”不能在asp.net核心上运行
- asp.net – 从用户控件内添加页面控件集合
- asp.net-mvc – asp.net mvc Ajax.BeginForm
- ASP.net中的字符串比较(C#)
- asp.net – 无效的安全证书和域名
- asp.net – 在.net 3.5 SP1中设置表单的操作会在编译时导致