所以,我不确定发生了什么。我的老板对我使用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; 使用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!";
}
}
}
}
答案 0 :(得分: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>