只允许使用内容控件(C# webcontrols)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14467650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Only Content Controls are Allowed (C# webcontrols)
提问by
So, I'm not sure what's going on. My boss wasn't pleased with me using MVC and Razor, so I'm being forced to code with this nasty webcontrol/codebehind style. =/
所以,我不确定发生了什么。我的老板对我使用 MVC 和 Razor 不满意,所以我被迫使用这种讨厌的 webcontrol/codebehind 风格进行编码。=/
The error is:
错误是:
Only Content controls are allowed directly in a content page that contains Content controls.
Here is the masterpage:
这是母版:
<%@ 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>
And here is the Default.aspx page that's throwing the error.
这是引发错误的 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>
And the silly Default.aspx.cs codebehind...
还有愚蠢的 Default.aspx.cs 代码隐藏......
using System; using System.Web; using System.Web.UI;
使用系统;使用 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!";
}
}
}
}
采纳答案by Sean Airey
All of your content, including static HTML must be inside Content
tags in the content page. You have a <h2>
outside:
您的所有内容,包括静态 HTML,都必须Content
位于内容页面的标签内。你有一个<h2>
外部:
<h2>Application Form</h2>
<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">
Should be:
应该:
<asp:Content id="content" ContentPlaceHolderID="contentPlaceHolder" runat="server">
<h2>Application Form</h2>