MVC: Drop-down List

Populate the list of drop-down options (using “ID” and “Description”) from within the Controller:

 
ViewBag.DropDownOptions = new SelectList(
        obj.GetDropDownOptions(), 
        "ID", 
        "Description", 
        string.Empty);

Then create a Drop-Down List within the View. Model.ID should refer to the source value, and then the list of options:

@Html.DropDownListFor(
    model => model.ID, 
    (IEnumerable)ViewData["DropDownOptions"])

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.