【发布时间】:2015-04-02 18:02:37
【问题描述】:
这很奇怪,或者我只是不明白它是如何工作的。我有以下代码:
<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="mySelect" 替换@style 位也不起作用...
谢谢!
【问题讨论】: