tags:

views:

241

answers:

1

Hi, I have a web service response of type AutomatOwners[] where AutomatOwners consists of two fields ID and Name. I would like to create a select list and then present it as dropdownlist, where Name would be displayed as an option and ID would be its option value. My idea was something like this:

ViewData["automat_owners"] = new SelectList((AutomatOwners[])web_service_response);

and in the view:

<%= Html.DropDownList("Owner", (SelectList)ViewData["automat_owners"]) %>

but obviously that is not enough. Any ideas?

+1  A: 

Try this


ViewData["automat_owners"] = new SelectList(web_service_response as IEnumerable, "ID", "Name");
Tadas