I\'m using ASP.NET MVC, and am trying to render a select list with the HtmlHelper.DropDownListFor method, like so:
<%= Html.DropDownListFor(x => x.AllT
DropDownList and derivatives don't support the functionality you're looking for. But you could also simply process the string returned by DropDownList.
<%=
Html.DropDownListFor(x => x.AllTopics,
SelectListHelper.GetSelectListItems(Model.AllTopics),
"Select a Topic",
new { id = "allTopics", @class = "topic-dropdown" })
.Replace("<option", "<option attr=\"value\"")
%>
Looking at the MVC source code, DropDownListFor uses DropDownList, which uses SelectInternal, which uses ListItemToOption, which wraps calls to TagBuilder. You could modify and include this source to accept extra calls to TagBuilder when the actual option tag is built.