Adding a css class to select using @Html.DropDownList()

后端 未结 10 1691
情深已故
情深已故 2020-11-30 01:13

I\'m building my first MVC application after years of doing webforms, and for some reason I am not able to make this work:

@Html.DropDownList(\"PriorityID\"         


        
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 01:24

    Simply Try this

    @Html.DropDownList("PriorityID", (IEnumerable)ViewBag.PriorityID,  new { @class="dropdown" })
    

    But if you want a default value or no option value then you must have to try this one, because String.Empty will select that no value for you which will work as a -select- as default option

    @Html.DropDownList("PriorityID", (IEnumerable)ViewBag.PriorityID, String.Empty, new { @class="dropdown" })
    

提交回复
热议问题