I have an IDictionary, now I want to use these values in a selectlist. How do I do this?
Thanks.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With