Reputation: 24515
How can I set a select class and other attributes eg:events through the SelectList
object?
If this cannot be done, what are the best practices in populating a select input (dropdownlist) ie should I just loop through the items and render the <option>
tags
I guess events should be bound to the controls in jquery for instance, but I do need the class forto do this.
Upvotes: 1
Views: 1052
Reputation: 1904
The htmlAttributes parameter should take an anonymous type initialised like this :
new {@class="some-css-class"}
Upvotes: 3
Reputation: 24832
<%=Html.DropDownList("elementname",yourSelectList,"defaultvalue",new{@class="yourclass"}) %>
Upvotes: 1