Dynamically bind data to dropdownlist in asp.net mvc

asp.net-mvc, data-binding

Solution

Just pass the correct IEnumerable as the typed model or ViewData. Try something like this (out of my head):

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

With that drop down list helper in MVC, you do not really "bind" data to it in the way it is done in the old ASP.NET.

Problem

How to dynamically bind data to `<%Html.Dropdownlist....` in ASP.NET MVC?

Original source