I would like the ability to add Html attributes to individual SelectListItems via object htmlAttributes. This would be handy for applying CSS to selected options on render. I have working code for this (using the MVC3 source as the base) that I have used on client websites so it will be easy to integrate.
Comments: I'm not sure if there's much more to add, @HongmeiG. I would envision a new property (of type System.Object) on SelectListItem (maybe called "Attributes" or "HtmlAttributes"), assigned using a syntax similar to the one I posted in my comment (a Func<Object, Object> parameter to the SelectList ctor). Then any call to @Html.DropDown and its ilk would honour that property and generate data- attributes for each <option> element. Does that make sense?
Comments: I'm not sure if there's much more to add, @HongmeiG. I would envision a new property (of type System.Object) on SelectListItem (maybe called "Attributes" or "HtmlAttributes"), assigned using a syntax similar to the one I posted in my comment (a Func<Object, Object> parameter to the SelectList ctor). Then any call to @Html.DropDown and its ilk would honour that property and generate data- attributes for each <option> element. Does that make sense?