IEnumerable to SelectList, no value is selected


I have something like the following in an ASP.NET MVC application:

IEnumerable<string> list = GetTheValues();
var selectList = new SelectList(list, "SelectedValue");

And even thought the selected value is defined, it is not being selected on the view. I have this feeling I'm missing something here, so if anyone can put me out my misery!

I know I can use an annoymous type to supply the key and value, but I would rather not add the additional code if I didn't have to.

EDIT: This problem has been fixed by ASP.NET MVC RTM.

3/19/2009 10:40:21 AM

If you're just trying to to map an IEnumerable<string> to SelectList you can do it inline like this:

new SelectList(MyIEnumerablesStrings.Select(x=>new KeyValuePair<string,string>(x,x)), "Key", "Value");
3/21/2012 7:02:49 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow