MVC - bootstrap -form控件将与form-group进入下一行

时间:2014-02-12 06:33:03

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

我想使用bootstrap formgroup。如果我有一个标签&一个控件,但是如果有超过2个控件(标签,控制和验证字段),那么验证字段会进入下一行。

我尝试使用form-inline但没有运气。任何人都可以告诉我如何将表单组的所有元素保存在一行中吗?

        <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>

1 个答案:

答案 0 :(得分: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>