ASP.NET MVC 嵌套母版页,继承内容
我有一系列嵌套母版页,如下所示:
site.master:
<asp:ContentPlaceHolder ID="SearchFormContent" runat="server">
<%Html.RenderPartial("SearchFormControl"); %>
</asp:ContentPlaceHolder>
在嵌套(子)母版页中,area.master
<asp:Content ContentPlaceHolderID="SearchFormContent" ID="SearchFormContentContainer" runat="server">
<asp:ContentPlaceHolderID="SearchFormContent" runat="server"/>
</asp:ContentPlaceHolder>
我有两个单独的内容页面。一个想要将自己的内容添加到 SearchFormContent,另一个想要保留在顶级母版页中定义的内容。当然,由于子母版页定义了 SearchFormContent 块的内容,以便子页可以访问它,因此顶级母版页中定义的内容将被删除。
有办法做到这一点吗?
I have a series of nested master pages, like so:
site.master:
<asp:ContentPlaceHolder ID="SearchFormContent" runat="server">
<%Html.RenderPartial("SearchFormControl"); %>
</asp:ContentPlaceHolder>
in the nested (child) master page, area.master
<asp:Content ContentPlaceHolderID="SearchFormContent" ID="SearchFormContentContainer" runat="server">
<asp:ContentPlaceHolderID="SearchFormContent" runat="server"/>
</asp:ContentPlaceHolder>
I have two separate content pages. One wants to add its own content to SearchFormContent, the other would like to keep the content that was defined in the top-level master page. Of course, since the child master page defines content for the SearchFormContent block so that the child pages can potentially access it, the content defined in the top level master page is obliterated.
Any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了在您的子母版页中包含以下内容之外,我想不出任何其他方法,
我知道令人讨厌,但这是我在使用母版页时能想到的唯一方法。
HTH,
查尔斯
I can't think of any way other than having the following in your child master page
Nasty I know, but its the only way I can think of when using master pages.
HTHs,
Charles
删除所有
ContentPlaceHolder
并将SearchFormControl
直接保留在 site.master 上。如果您不想覆盖SearchFormControl
那么您不需要定义ControlPlaceHolder
Remove all your
ContentPlaceHolder
s and leave theSearchFormControl
directly on the site.master. If you never want to override theSearchFormControl
then you don't need to define theControlPlaceHolder
s您可以将内容放入母版页上的 contentPlaceHolder 中。如果您不使用子页面上的内容覆盖,则默认情况下会呈现该内容。
you can put content in the contentPlaceHolder on the masterpage. that will be rendered by default if you don't override the with a content on a child page.