Вы неправильно понимаете, как работает std::variant
operator<
. Сначала он сравнивает индексы и только если индексы равны, он сравнивает значения: https://en.cppreference.com/w/cpp/utility/variant/operator_cmp . Для неравных индексов он возвращает true
, если индекс по первому варианту меньше, чем по второму.
DropDownList и его производные не поддерживают функциональность, которую вы ищете. Но вы также можете просто обработать строку, возвращаемую 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.