ASP.NET MVC: putting custom attributes into option tag in select list

后端 未结 2 1640
一整个雨季
一整个雨季 2021-01-01 11:00

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         


        
2条回答
  •  梦谈多话
    2021-01-01 11:50

    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("
    

提交回复
热议问题