7

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

1 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.