tags:

views:

30

answers:

2

Hi, I'd like to create a dropdownlist from following structure

List<KeyValuePair<long, string>> sponsori = 
    new List<KeyValuePair<long, string>>();

Now I want the selectlist to have the pair's long as data value, the string as text value and the selected item, if I have only access to the long of the selected item.

THanks in advance.

+1  A: 

In your action code

 yourViewModel.Sponsori= new SelectList(sponsori, "Key", "Value")

In your view code

<%=Html.DropDownList("yourSelectid", Model.Sponsori) %>
Gregoire
+1  A: 
ViewData["selectList"] = new SelectList(sponsori, "Key", "Value");

And then on the page:

<%= Html.DropDownList("selectList") %>

You can also check out Rendering a Form in ASP.NET MVC Using HTML Helpers for a similar example (and more documentation).

Justin Niessner