How to create a DropDown list from IDictionary using Razor in ASp.Net Mvc3?? I=m trying the following code wit no success.
public IDictionary<string, string> CandidatesList = new Dictionary<string, string>();
Html.DropDownListFor(modal => modal.CandidatesList, new SelectList(Model.CandidatesList, "Value", "Key"))
Don’t bind the dropdown to the same property as the second argument. You must bind it to a primitive type property on your model:
where
SelectedCandidateKeymust be a string property on your view model which will hold the selected item key.Think of it this way: when you need a dropdownlist in ASP.NET MVC you have to declare 2 properties on your view model:
IEnumerable<SelectListItem>property that will hold all the available values