我想将自定义类添加到Asp.net Razor MVC控件@Html.DropDownListFor
我有以下代码
@Html.DropDownListFor(model => model.is_admin, new SelectList(
new List<Object>{
new { value = "true" , text = "Admin" },
new { value = "false" , text = "User" },
},
"value",
"text",
"false" ))
如何在Asp.net MVC 5中实现相同的控件
答案 0 :(得分:1)
添加第三个名为htmlAttributes
的参数,如下所示。
@Html.DropDownListFor(model => model.is_admin,
new SelectList(
new List<Object>{
new { value = "true" , text = "Admin" },
new { value = "false" , text = "User" },
}, "value", "text", "false"),
new { @class = "your_class_name" });