【问题标题】:MVC - bootstrap -form control is coming in next line with form-groupMVC - bootstrap -form 控件与 form-group 一起出现在下一行
【发布时间】:2015-03-16 01:46:34
【问题描述】:

我想使用引导表单组。如果我有一个标签和一个控件,它可以工作,但如果有超过 2 个控件(标签、控件和验证字段),则验证字段进入下一行。

我尝试使用 form-inline 但没有运气。谁能告诉我如何将 form-group 的所有元素放在一行中?

        <div class="form-group">
            @Html.Label("Emp ID", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.EmpID, new { disabled = "disabled", @class = "form-control" })
            </div>
        </div>

        @* Tried with form-group *@
        <div class="form-group">
            @Html.LabelFor(model => model.EmployementTypeID, Constants.EmploymentType, new { @class = "col-sm-2 control-label" })
            <div>
                @Html.DropDownListFor(model => model.EmployementTypeID, new SelectList(Model.EmploymentType, "EmployementTypeID", "EmployementTypeName", Model.EmployementTypeID), new { @class = "form-control" })
              @* This validation goes in next line, how can we keep it in the same line *@
                @Html.ValidationMessageFor(model => model.EmployementTypeID)
            </div>
        </div>

        @* Tried with form-inline *@
        <div class="form-inline">
            @Html.LabelFor(model => model.Address, Constants.Address, new { @class = "col-sm-2 control-label" })
            <div>
                @Html.TextAreaFor(model => model.Address, new { @class = "form-control col-sm-10" })
           @* This validation goes in next line, how can we keep it in the same line *@
                @Html.ValidationMessageFor(model => model.Address)
            </div>
        </div>

【问题讨论】:

    标签: asp.net-mvc twitter-bootstrap model-view-controller twitter-bootstrap-3


    【解决方案1】:

    尝试将您的 class="col-sm-10" 添加到您的所有 div 中。

    像这样:

    <div class="form-group">
        @Html.LabelFor(model => model.EmployementTypeID, Constants.EmploymentType, new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.DropDownListFor(model => model.EmployementTypeID, new SelectList(Model.EmploymentType, "EmployementTypeID", "EmployementTypeName", Model.EmployementTypeID), new { @class = "form-control" })                  
            @Html.ValidationMessageFor(model => model.EmployementTypeID)
        </div>
    </div>
    

    【讨论】:

    • 这是正确的在 asp mvc 中使用 Bootstrap Horizo​​ntal Form 的方法检查 here 了解更多信息。
    猜你喜欢
    • 2014-04-10
    • 2016-09-27
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    • 2020-10-26
    • 2017-11-09
    相关资源
    最近更新 更多