c# - 为什么此按钮在 ASP.NET MVC CSS 中显示在表格上方而不是下方

标签 c# html css asp.net-mvc

我不知道为什么,但是当我运行应用程序时,这个按钮显示在表格上方。此按钮应位于此表下方。我该如何解决这个问题?

 <table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.MyList.FirstOrDefault().Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.MyList.FirstOrDefault().Amount)
        </th>
    </tr>

    @using (Html.BeginForm())
    {
        @Html.ValidationSummary("", new { @class = "text-danger" })
        <br />
        for (var i = 0; i < Model.MyList.Count; i++)
        {
            <tr>
                <td>
                    @Html.DisplayFor(model => model.MyList[i].Name)
                    @Html.HiddenFor(model => model.MyList[i].Name)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.MyList[i].Amount)
                    @Html.HiddenFor(model => model.MyList[i].Amount)
                </td>
            </tr>

        }
        <input type="submit" value="Confirm" class="btn btn-success" />
    }
</table>

最佳答案

试试这个。您正在将表格代码与其余的 Html 混合

@using (Html.BeginForm())
{
    @Html.ValidationSummary("", new { @class = "text-danger" })
    <br />
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.MyList.FirstOrDefault().Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.MyList.FirstOrDefault().Amount)
            </th>
        </tr>


        @for (var i = 0; i < Model.MyList.Count; i++)
        {
            <tr>
                <td>
                    @Html.DisplayFor(model => model.MyList[i].Name)
                    @Html.HiddenFor(model => model.MyList[i].Name)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.MyList[i].Amount)
                    @Html.HiddenFor(model => model.MyList[i].Amount)
                </td>
            </tr>
        }
    </table>
    <input type="submit" value="Confirm" class="btn btn-success" />
}

关于c# - 为什么此按钮在 ASP.NET MVC CSS 中显示在表格上方而不是下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36234230/

相关文章:

c# - 检查泛型类型是否继承自泛型接口(interface)

c# - 安装好vs2015后如何在vs2015上安装Asp.Net?

javascript - 有没有办法在没有指定宽度或高度的情况下使 div 居中?

javascript - Angular 模板中的 Concat 范围

javascript - 全屏滑动div不同大小和方向

javascript - 单击时隐藏 <nav>

c# - 如何在不定义路径的情况下读取现有文本文件

c# - 如何使用 .NET 高效地为 FAST ESP 提供千兆字节的数据

css - 如何在 CSS3 中为不同的屏幕分辨率定义 x、y 轴

Javascript ScrollTo anchor