简体   繁体   English

ASPP页面上的ASP.NET MVC错误

[英]asp.net mvc Error on aspx page

I'm getting a only asp.net runtime error "content controls are allowed directly in a content page that contains content controls." 我收到一个唯一的asp.net运行时错误“在包含内容控件的内容页面中直接允许内容控件”。

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <% using (Html.BeginForm("", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
       {%>

    <input type="file" name="FileUpload" />
    <input type="submit" name="Submit" id="Submit" value="Upload" />

<% }
        System.Data.DataTable dt = (System.Data.DataTable) (ViewData["dt"]);
        if (dt != null && dt.Rows.Count > 0)
        {
            foreach (System.Data.DataRow dr in dt.Rows)
            {
                for (int i = 0; i < dt.Columns.Count ; i++)
                {%>

  <span><%= dr[i].ToString()%></span>
        <% }%>
           <br/>
            <%}
        }%>


</asp:Content>

"content controls are allowed directly in a content page that contains content controls." “直接在包含内容控件的内容页面中允许内容控件。”

You are getting this error because you have added server controls to your view: 您收到此错误是因为您已将服务器控件添加到视图中:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

This require ViewState (webforms) such notion do not exist in ASP.net MVC. 这要求ViewState(webforms)这样的概念在ASP.net MVC中不存在。

Just as an example, your view would look like this: 仅作为示例,您的视图将如下所示:

View 视图

@model YourProject.YourModel

@using (Html.BeginForm("", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="FileUpload" />
    <input type="submit" name="Submit" id="Submit" value="Upload" />
}

@foreach (var item in YourModel.data)
{
    <span>@item</span>
}

In your Controller you will put the logic. 在您的控制器中,您将放置逻辑。

In your Model you will put properties there for your objects. 在模型中,您将在其中放置对象的属性。

Never manipulate data in your View. 切勿在视图中操作数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM