将数据动态绑定到asp.net mvc中的下拉列表

use*_*215 7 data-binding asp.net-mvc

如何<%Html.Dropdownlist....在ASP.NET MVC中动态绑定数据?

han*_*ngy 15

只需将正确的IEnumerable作为类型化模型或ViewData传递即可.尝试这样的事情(从我的头脑中):

<%= Html.DropDownList(string.Empty, 
    "myDropDownList",  
    new SelectList((IEnumerable)ViewData["stuff"], 
        "DescriptionProperty", 
        "ValueProperty")) 
%>
Run Code Online (Sandbox Code Playgroud)

使用MVC中的下拉列表帮助程序,您不会像在旧ASP.NET中那样"绑定"数据.