css - 无法使用 Bootstrap 3 在 MVC Razor View 中应用控件对齐

标签 css asp.net-mvc html razor twitter-bootstrap-3

问题陈述:

在我的编辑 View 之一中,我想禁用文本框,因此为此我使用 DisplayFor 而不是 TextboxFor。但是当我使用 Displayfor 时,对齐方式不正确。您可以查看所附图片以供引用。我正在使用 Bootstrap CSS 3.0

如有任何帮助,我们将不胜感激。我应该使用什么内联 CSS 来正确对齐??

Image1:在此图中,您可以看到 Acquire Status ID 标签和 Textboxfor 正确对齐。 enter image description here

Image2:当我使用 DisplayFor 而不是 Textboxfor 时,Acquire Status ID 标签和 Displayfor 没有正确对齐。

enter image description here

查看:

<div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true)

        <div class="form-group">
            @Html.LabelFor(model => model.AcquirestatusID, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DisplayFor(model => model.AcquirestatusID,new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.AcquirestatusID)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Name)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>

最佳答案

我使用 Textboxfor 的只读属性解决了我的问题。

 @Html.TextBoxFor(model => model.AccessoriesID,new { @class = "form-control",@readonly="readonly" })

应用以上代码行后,我的编辑 View 如下所示:

enter image description here

关于css - 无法使用 Bootstrap 3 在 MVC Razor View 中应用控件对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23753452/

相关文章:

javascript - 为什么id不变?

html - 使用下一个图像组件保留图像的纵横比

css - selectManyButton 的自定义 .ui-state-active 样式

html - 如何将先前的输入值插入文本区域?

asp.net-mvc - 洋葱架构——服务层职责

asp.net-mvc - 在 MVC2 中的 EditorForModel 与 DisplayForModel 模式中显示不同的字段

html - 子菜单中的三 Angular 形与主菜单项重叠

html - CSS 属性显示问题 : inline-block

asp.net - MVC3远程模型验证操作中的参数名称

html - CSS Grid 固定高度和可变宽度