Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Sep 15, 2008 11:34 PM|LINK
Well... probably you mistyped some variable name, but this was not the real problem.
You must tell the SelectList how to bind the list and which property of the object is used for the text and which for the data, so, since each element in the dictionary is a KeyValuePair the controller should be:
public ActionResult SelectSample()
var dict = new Dictionary<string, string>();
ViewData["Targets"] = new SelectList(dict,"Value","Key");
Then the DropDownList can also be called with the easy overload:
<%= Html.DropDownList("","Targets") %>
The easy overload automatically probes both the ViewData dictionary and the model, so no need to do all the conditional binding you are doing in your code.