bootstrap form-group control-label missplaced

时间:2015-08-18 06:14:33

标签: c# asp.net-mvc twitter-bootstrap razor

我有一个表单组,其中标签拼写错误,标签与下拉列表相比太远,请参阅图片。

Missplaced label

这是我的代码:

<div class="form-group">
  <div class="col-lg-2"></div>
  @Html.LabelFor(model => model.deviceModel, "OS:", htmlAttributes: 
    new { @class = "col-lg-2 control-label" })
  <div class="col-lg-4">
    @Html.DropDownListFor(model => model.deviceModel, new SelectListItem[]{ 
      new SelectListItem{Value = "1", Text="iOS"},
      new SelectListItem{Value = "2", Text="Android"}}, 
      new { htmlAttributes = new { @class = "form-control" } })
   </div>
   <div class="col-lg-2"></div>
 </div>

我做错了什么,为什么错过了?

1 个答案:

答案 0 :(得分:1)

我不是进入C#和Razor,但根据我的评论并查看代码,下拉列表的htmlAttributes前面的new看起来不对。似乎该类未应用于下拉列表,这可能会导致移位,可能是由不同的边距参数引起的。

<div class="form-group">
  <div class="col-lg-2"></div>
  @Html.LabelFor(model => model.deviceModel, "OS:", 
    htmlAttributes: new { @class = "col-lg-2 control-label" })
  <div class="col-lg-4">
  @Html.DropDownListFor(model => model.deviceModel, new SelectListItem[]{ 
    new SelectListItem{Value = "1", Text="iOS"},
    new SelectListItem{Value = "2", Text="Android"}}, 
    htmlAttributes: new { @class = "form-control" } )
  </div>
<div class="col-lg-2"></div>