gpt4 book ai didi

asp.net-mvc - MVC - bootstrap -form 控件与 form-group 一起出现在下一行

转载 作者:行者123 更新时间:2023-12-03 19:04:47 25 4
gpt4 key购买 nike

我想使用 Bootstrap 表单组。如果我有一个标签和一个控件,它就可以工作,但如果有超过 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>

最佳答案

尝试将您的 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.net-mvc - MVC - bootstrap -form 控件与 form-group 一起出现在下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21720399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com