Best way of implementing DropDownList in ASP.NET MVC 2?

后端 未结 5 2068
小蘑菇
小蘑菇 2020-12-09 19:40

I am trying to understand the best way of implementing a DropDownList in ASP.NET MVC 2 using the DropDownListFor helper. This is a multi-part ques

5条回答
  •  一生所求
    2020-12-09 19:58

    You could do something like:

    <%= Html.DropDownListFor((x => x.ListItems), Model.ListItems, "")%>
    

    or

    <%= Html.DropDownList("ListItems", Model.ListItems, "")%>
    

    The last param 'optionLabel' makes a blank list item

    In this case, you can see ListItems is a property of the model.

    I have made the view strongly typed to the model also.

提交回复
热议问题