我在ASP.NET MVC中执行应用程序,并且我使用不同国家/地区的Enum作为下拉列表。该列表正在运行,但与具有Bootstrap样式的其他输入字段相比,它看起来就像一个没有样式的列表。可能有什么不对?
<div class="form-group">
@Html.LabelFor(model => model.Country, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*@Html.EditorFor(model => model.Country, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.EnumDropDownListFor(model => model.Country, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Country, "", new { @class = "text-danger" })
</div>
</div>
答案 0 :(得分:2)
您将htmlAttribues
参数及其值再次包装在匿名对象中。只需删除它就可以了。
更改
@Html.EnumDropDownListFor(model => model.Country,
new { htmlAttributes = new { @class = "form-control" } })
到
@Html.EnumDropDownListFor(model => model.Country,
htmlAttributes : new { @class = "form-control" })
或简单地说,
@Html.EnumDropDownListFor(model => model.Country, new { @class = "form-control" })