【问题标题】:Correct way to display a MVC Form using bootstrap使用引导程序显示 MVC 表单的正确方法
【发布时间】:2015-03-08 02:30:54
【问题描述】:

我正在使用表单来捕获用户的各种项目,但我似乎无法让它们以我想要的方式显示。

我正在使用引导程序来创建 2 列文本框及其相关标签。
不幸的是,当它到达最后一个 EditorFor 时,它的显示与其余部分不一致。
我是否使用了错误的 div 和列选项?
另外,我将如何在文本框的顶部和底部之间添加一些空间?
在css中使用填充?

我希望最后一个标签从左侧开始,然后文本框与其对齐并占用该列中的其余空间,也许在行之间添加一点空间。

这是我视图中的代码

@model iskbv5.Models.Vendor

@{
    ViewBag.Title = "Add New Vendor";
}

<h2>@ViewBag.Title</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <hr />
    <div class="form-group">
        <div class="control-label col-md-2">
            Vendor Name
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
        </div>
    </div>
    <div class="form-group">
        <div class="control-label col-md-2">
            Vendor Website
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.Website, new { htmlAttributes = new { @class = "form-control" } })
        </div>
    </div>
    <div class="form-group">
        <div class="control-label col-md-2">
            Vendor Address
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
        </div>
    </div>
    <div class="form-group">
        <div class="control-label col-md-2">
            Vendor Username
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.Username, new { htmlAttributes = new { @class = "form-control " } })
        </div>
    </div>
    <div class="form-group">
        <div class="control-label col-md-2">
            User Managing the Vendor
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.ManagingUser, new { htmlAttributes = new { @class = "form-control" } })
        </div>
    </div>
    <div class="form-group">
        <div class="control-label col-md-2">
            Vendor Password
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
        </div>
    </div>
    <div class="form-group">
        <div class="control-label col-md-2">
            Reason We Use the Vendor
        </div>
        <div class="col-md-4">
            @Html.EditorFor(model => model.Usage, new { htmlAttributes = new { @class = "form-control" } })
        </div>
    </div>
        <div class="col-md-12">
            <input type="submit" value="Create" class="btn btn-xs btn-primary" /> or
            <a href="@Url.Action("Index")" class="btn btn-xs btn-default">Cancel</a>
        </div>
        }

我将 Usage 属性设置为

[DataType(DataType.MultilineText)]
public string Usage { get; set; }

这是它当前的显示方式。

【问题讨论】:

  • 您的列(col-md-4 等)需要有一个围绕它们的元素,即 row。以&lt;div class='row'&gt; 为例。不过,不确定这是否是您唯一的问题。
  • 修复了与最后一行内联之间的空间,但它们似乎在右侧稍微偏移了一点。 i.imgur.com/80qHvRe.jpg
  • 啊,经过一些调整,并在每个“行”之间添加一个
    ,我得到了想要的外观。谢谢。 i.imgur.com/a7ZX3Ld.jpg

标签: c# html css twitter-bootstrap model-view-controller


【解决方案1】:

啊,经过一些调整,并在每个“行”之间添加&lt;br/&gt;,我得到了想要的外观。谢谢。

【讨论】:

  • 您好,您可以分享查看代码吗?我也有同样的问题。
猜你喜欢
  • 2020-11-19
  • 1970-01-01
  • 2013-02-10
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 2018-06-13
相关资源
最近更新 更多