Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDictionary to SelectList?

I have an IDictionary, now I want to use these values in a selectlist. How do I do this?

Thanks.

like image 685
Tony Borf Avatar asked May 11 '09 14:05

Tony Borf


Video Answer


1 Answers

Just set "Value" and "Key" for dataValueField and dataTextField. You can either do this in your View itself or from your action (haven't tested the code below).

 var targets = new Dictionary<string, string>(); targets.Add("Key", "Value");  ViewData["MyList"] = new SelectList(targets, "Key", "Value"); 
like image 168
David Avatar answered Nov 12 '22 18:11

David