Asp.net asp mvc的Html呈现顺序

Asp.net asp mvc的Html呈现顺序,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我的表格怎么会这样 这是我的密码: @using MvcApplication6.Models; @model List<Employee> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> <a href="@Url.Action("Create")">Create Entry</a> </p> <p>@Html.ActionLin

我的表格怎么会这样

这是我的密码:

@using MvcApplication6.Models;
@model List<Employee>

@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
    <a href="@Url.Action("Create")">Create Entry</a>
</p>
<p>@Html.ActionLink("Check departments", "Index", "Department")</p>
<p><a href="@Url.Action("Summary")">Check summary</a></p>

<table border="1">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model[0].id)
        </th>
        <th>
            @Html.LabelFor(model => model[0].firstname)
        </th>
        <th>
            @Html.LabelFor(model => model[0].lastname)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].gender)
        </th>
        <th>
            @Html.DisplayNameFor(model => model[0].department)
        </th>
        <th>Action</th>
    </tr>

    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        foreach (Employee mod in Model)
        {
            <tr>
                <td>
                    <input type="hidden" value="@mod.id" name="id" id="id" />
                    @Html.DisplayFor(modelItem => mod.id)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => mod.firstname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => mod.lastname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => mod.gender)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => mod.department)
                </td>
                <td>
                    <button onclick="location.href='@Url.Action("Edit", new { id = mod.id })';return false;">Edit</button> 

                    @Html.CheckBoxFor(modelItem => mod.selected)
                </td>
            </tr>
        }
        <br />
        <input type="submit" value="submit" />
    }
    </table>
@使用mvcapapplication6.Models;
@模型列表
@{
ViewBag.Title=“Index”;
}
指数

@ActionLink(“检查部门”、“索引”、“部门”)

@Html.DisplayNameFor(模型=>model[0].id) @Html.LabelFor(model=>model[0].firstname) @Html.LabelFor(model=>model[0].lastname) @Html.DisplayNameFor(model=>model[0]。性别) @DisplayNameFor(模型=>模型[0]。部门) 行动 @使用(Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) foreach(模型中的员工模型) { @DisplayFor(modelItem=>mod.id) @DisplayFor(modelItem=>mod.firstname) @DisplayFor(modelItem=>mod.lastname) @DisplayFor(modelItem=>mod.gender) @DisplayFor(modelItem=>mod.department) 编辑 @CheckBoxFor(modelItem=>mod.selected) }
}
以下是我关注的问题:

请注意,我将我的
submit
按钮放在了
foreach
循环之后,但是为什么它是在实际框之前呈现的呢? 我一直试图把它放在底部,但我有一些问题。
渲染的顺序是什么?

您的html无效。
元素不能是
元素的子元素(也不是由
AntiForgeryToken
ValidationSummary
生成的元素。但如果您提交了表单,这将永远不会绑定到任何内容!oooo真的,我应该如何修复它?是的,我也在处理这个问题。表单和相关复选框的用途是什么(您提交表单时需要哪些信息)好的,让我来修正我的问题。我会删除这个问题,并提出另一个问题,因为我以某种方式修正了它。