6

所以,我不确定发生了什么。我的老板对我使用 MVC 和 Razor 不满意,所以我被迫使用这种讨厌的 webcontrol/codebehind 风格进行编码。=/

错误是:

Only Content controls are allowed directly in a content page that contains Content controls.

这是母版页:

<%@ Master Language="C#"%>
<!DOCTYPE html>
<html>
<head>
    <title>Application Form</title>
</head>
 <body>
    <div id="container">
        <asp:contentplaceholder id="contentPlaceHolder" runat="server" />
    </div>
</body>
</html>

这是引发错误的 Default.aspx 页面。

<%@ Page Language="C#" Inherits="dumb.Default" MasterPageFile="MasterPage.master" %>

<h2>Application Form</h2>
<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">
    <p>Please complete this application.</p>

    <form action="Default.aspx" method="post" runat="server">
            <div>
                    <span class="spaced">Name:</span><asp:TextBox id="name" runat="server" />
            </div>
    </form>
    <p>
            <asp:Label id="finalmessage" runat="server" />
    </p>
</asp:Content>

还有愚蠢的 Default.aspx.cs 代码隐藏......

使用系统;使用 System.Web;使用 System.Web.UI;

namespace dumb
{
    public partial class Default : System.Web.UI.Page
    {
            protected void Page_Load (object sender, EventArgs e)
            {
                    if (IsPostBack) {
                            finalmessage.Text = "Submission Processed Successfully!";
                    }
            }
    }
}
4

1 回答 1

10

您的所有内容(包括静态 HTML)都必须Content位于内容页面的标签内。你有一个<h2>外部:

<h2>Application Form</h2>
<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">

应该:

<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">
    <h2>Application Form</h2>
于 2013-01-22T20:50:30.370 回答