[英]C# MVC : Putting Html.EditorFor and Html.DropDownListFor on same line
I have a Razor
view which I would like to put a text field (implemented via @Html.EditFor
) side by side with a drop down list (implemented via @Html.DropDownListFor
). 我有一个
Razor
视图,我想将一个文本字段(通过@Html.EditFor
实现)与一个下拉列表(通过@Html.DropDownListFor
实现)并排放置。 However, when doing using these inside the same div, the drop down list is being put on the next line. 但是,当在同一个div中使用它们时,下拉列表将放在下一行。 How can I overcome this?
我该如何克服?
<div class="form-group">
@Html.LabelFor(model => model.Size.SizeNutFacts.BaseUnitAmount, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Size.SizeNutFacts.BaseUnitAmount, new { htmlAttributes = new { @class = "form-control" } })
@Html.DropDownListFor(m => m.SelectedBaseUnit, Model.BaseUnitOptions, "Select Unit", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Size.SizeNutFacts.BaseUnitAmount, "", new { @class = "text-danger" })
</div>
</div>
You need to add a wrapper class div with inline-block
around your editor and dropdownlist that prevents them filling up the whole line, thus rendering them next to eachother, like this: 您需要在编辑器和下拉列表周围添加带有
inline-block
的包装类div,以防止它们填满整行,从而使它们彼此相邻,如下所示:
.wrapper {
display: inline-block;
}
http://jsfiddle.net/aY9HC/749/ http://jsfiddle.net/aY9HC/749/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.