开发者

ASP.NET MVC nested master pages, inherit content

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="Sea开发者_StackOverflowrchFormContent" 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?


I can't think of any way other than having the following in your child master page

<asp:Content ContentPlaceHolderID="SearchFormContent" ID="SearchFormContentContainer" runat="server">
    <asp:ContentPlaceHolder ID="SearchFormContent" runat="server">
        <%Html.RenderPartial("SearchFormControl"); %>
    </asp:ContentPlaceHolder>
</asp:ContentPlaceHolder>

Nasty I know, but its the only way I can think of when using master pages.

HTHs,
Charles


Remove all your ContentPlaceHolders and leave the SearchFormControl directly on the site.master. If you never want to override the SearchFormControl then you don't need to define the ControlPlaceHolders


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜