views:

329

answers:

2

I have an application, that shows list of items bound to a typed model.

In the list every item has an ID from a lookup table.

How to show the value of the lookup data for each item instead of IDs?

The best way has to link a html dropdownlist to each ID, from where I would be able to choose the appropriate value.

Thanks in advance

Gabrile

+1  A: 

Well the first step is to make sure you get all of the values that will be in the DropDownList. You should be able to easily fetch this from your database.

Set the text of the DropDownList items to the text value for the lookup item, and set the value to the ID of those same items.

When creating the DropDownList make sure to set the Selected one to be the option which matches the ID of your modeled data item.

Brendan Enrick
A: 

The answer I found here, that works:

http://stackoverflow.com/questions/1785410/asp-net-mvc-and-linq-to-entities-how-to-include-text-value-from-ienumerablesel

The only question remained for me: in that solution I can grab the value for the ID, but how to set a dropdownList selected value to the ID value?

Gabrile