3

I want my master page to be divided in two parts - left and right.

Here's is how I do it:

The master page:

<section id="main">
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
        <div>
            <asp:ContentPlaceHolder ID="left" runat="server" />
        </div>
        <div>
            <asp:ContentPlaceHolder ID="right" runat="server" />
        </div>
    </section>
</asp:ContentPlaceHolder >

The About view:

<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Content ID="leftHome" ContentPlaceHolderID="left" runat="server">
        <h2>About</h2>
    </asp:Content>
    <asp:Content ID="rightHome" ContentPlaceHolderID="right" runat="server">
        <h2>About</h2>
    </asp:Content>
</asp:Content>

I get the error: Content controls have to be top-level controls in a content page or a nested master page that references a master page.

How to resolve this?

4

1 回答 1

1

你不能有这样的嵌套。以下是您可以在母版页中执行的操作:

<section id="main">
    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
    <div>
        <asp:ContentPlaceHolder ID="left" runat="server" />
    </div>
    <div>
        <asp:ContentPlaceHolder ID="right" runat="server" />
    </div>
</section>

在视图中:

<asp:Content ID="leftHome" ContentPlaceHolderID="left" runat="server">
    <h2>Left content</h2>
</asp:Content>

<asp:Content ID="rightHome" ContentPlaceHolderID="right" runat="server">
    <h2>Right content</h2>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    some main content
</asp:Content>
于 2012-04-07T07:36:43.000 回答