这很奇怪,或者我只是不明白这是如何工作的。我有以下代码:
<div class="form-group">
@Html.LabelFor(model => model.Department, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(dep=>dep.DepartmentId,new SelectList(ViewBag.Departments,"Id","Name"), new {htmlAttributes = new {@class="mySelect"}})
@Html.ValidationMessageFor(model => model.Department, "", new { @class = "text-danger" })
</div>
</div>
样式表条目:
.mySelect {
width: 5000px;
border: groove;
}
以上组合不会格式化我的下拉列表,但如果我执行直接格式化,则可以使用:
<div class="form-group">
@Html.LabelFor(model => model.Department, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(dep=>dep.DepartmentId,new SelectList(ViewBag.Departments,"Id","Name"), new {@style = "width:500px;border:groove;"})
@Html.ValidationMessageFor(model => model.Department, "", new { @class = "text-danger" })
</div>
</div>
另外,如果我将@style添加到htmlAttribute部分,它不起作用,也不会用@class =&#34替换@style位; mySelect&#34; ...
谢谢!
答案 0 :(得分:0)
在没有@class
的情况下使用直接htmlAttributes
。
@Html.DropDownListFor(dep=>dep.DepartmentId,new SelectList(ViewBag.Departments,"Id","Name"), new { @class="mySelect" })