【问题标题】:Table with Html.EditorFor带有 Html.EditorFor 的表格
【发布时间】:2019-03-17 18:03:04
【问题描述】:

我正在尝试使用表格创建表单。我一共有7个字段。我希望完成的是一行有 3 个字段,第二行有 3 个字段,最后一行将是扩展的最后一个字段。我尝试使用 colspan 但是 NextAction 的 editorfor 框并没有一直延伸。此字段的右侧有一个边距。我尝试创建一个 CSS 类来消除边距,但效果不佳。

如何才能让 NextAction 字段一直延伸到最后一列?

下面我为表格的最后 2 行添加了代码。

            <table>
            <tr>
                <td>
                    @Html.LabelFor(model => model.Customer, htmlAttributes: new { @class = "control-label labelpadding" })
                </td>
                <td style="width:300px">
                    @Html.EditorFor(model => model.Customer, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Customer, "", new { @class = "text-danger" })
                </td>
                <td>
                    @Html.LabelFor(model => model.Principal, htmlAttributes: new { @class = "control-label col-md-2" })
                </td>
                <td style="width:300px">
                    @Html.EditorFor(model => model.Principal, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Principal, "", new { @class = "text-danger" })
                </td>

                <td>
                    @Html.LabelFor(model => model.Product, htmlAttributes: new { @class = "control-label labelpadding" })
                </td>
                <td>
                    @Html.EditorFor(model => model.Product, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Product, "", new { @class = "text-danger" })
                </td>

            </tr>
            <tr>

                <td>
                    @Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label labelpadding" })
                </td>
                <td>
                    @Html.DropDownListFor(m => m.Status, new SelectList(ViewBag.Status, "Status", "Text"), new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
                </td>
                <td>
                    @Html.LabelFor(model => model.Value, htmlAttributes: new { @class = "control-label labelpadding" })
                </td>
                <td>
                    @Html.EditorFor(model => model.Value, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Value, "", new { @class = "text-danger" })
                </td>
                <td>
                    @Html.LabelFor(model => model.FollowUpDate, htmlAttributes: new { @class = "control-label labelpadding" })
                </td>
                <td>
                    <div>
                        <div class="input-group date" data-provide="datepicker">
                            @Html.EditorFor(model => model.FollowUpDate, new { htmlAttributes = new { @class = "form-control" } })
                            <div class="input-group-addon">
                                <span class="glyphicon glyphicon-th"></span>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    @Html.LabelFor(model => model.NextAction, htmlAttributes: new { @class = "control-label labelpadding" })
                </td>
                <td colspan="5">
                    @Html.EditorFor(model => model.NextAction, new { htmlAttributes = new { @class = "form-control ", @style = "margin-right: 0 !important;"} })
                    @Html.ValidationMessageFor(model => model.NextAction, "", new { @class = "text-danger" })
                </td>
            </tr>
        </table>

【问题讨论】:

  • 能贴出完整的代码吗?
  • 我编辑了我的代码。我的桌子有完整的代码。
  • 看起来您正在使用引导程序。为什么使用 HTML 表格而不是 Bootstrap 的 CSS 类?你能确认你是否在使用 Bootstrap 吗?
  • 最初我使用的是引导程序,但列都搞砸了,所以我改用 HTML,因为我更了解它。
  • 您必须将所有其他单元格跨到并扩大您的表格。现在表格宽度是 3,而你想要 5 这是不可能的

标签: c# html css asp.net asp.net-mvc


【解决方案1】:

由于您在项目中启用了 Bootstrap,请使用 Bootstrap 的 CSS 类 w-100。此类将使其应用的元素具有 100% 的宽度。这是添加了该类的更新后的EditorFor 行:

@Html.EditorFor(model => model.NextAction, new { htmlAttributes = new { @class = "form-control w-100"} })

如果这不起作用,您可能有其他东西覆盖它。检查您的其他样式表和浏览器中呈现的 HTML。

【讨论】:

  • @user9448003 如果我回答了您的问题,请考虑将我的答案选为“最佳答案”。谢谢!
猜你喜欢
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-24
  • 1970-01-01
  • 2010-12-07
  • 2012-11-27
相关资源
最近更新 更多