Reputation: 6762
I am trying to apply css class for asp.net mvc dropdown list. It works for editorfor case but not for dropdownlistfor case. What may be the missing part from my code?
Working css class for dropdown
@Html.EditorFor(model => model.role, new { htmlAttributes = new { @class = "form-control" } })
failing css class for drowdown
@Html.DropDownListFor(model => model.role, new SelectList((IEnumerable)ViewData["Roles"], "role1", "role1"), new { htmlAttributes = new { @class = "form-control" } })
Upvotes: 1
Views: 889
Reputation: 3413
//DropDownListFor: modelItem, selectList, optionLabel, htmlAttributes
//EditorFor: modelItem, additionalViewData
If you "right click" the code and peek definition (in Visual Studio) you'll see the definitions. So if you use this, it should work:
@Html.DropDownListFor(model => model.role, new SelectList((IEnumerable)ViewData["Roles"], "role1", "role1"), null, new { @class = "form-control" })
Upvotes: 3