Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Sep 15, 2008 08:57 PM|LINK
On my ViewData I have a property name Target of type string which I want the user to select from one of the possible targets.
So I added a new property to my ViewData named Targets, of type SelectList, that holds the possible targets.
Now what I need is, on my view, display a DropDownList with all items from Targets and where the selected item is the one which value is contained in Target.
On my controller:
var dict = new Dictionary<string, string>();
viewData.Targets = new SelectList(targets);
Then on my view I have:
<%= Html.DropDownList("", "Targets", ViewData["Targets"] ?? ViewData.Model.Targets) %>
What I see in my DropDownList is:
[Blank, _blank], [Top, _top], ...
What am I doing wrong?
And how can I set the default value of the DropDownList to be the value contained in ViewData["Target"]