tags:

views:

75

answers:

2

Here is what I have in the controller:

IList<LocationInFacility> locs = LocationsInFacility(custCodeID);
ViewData["LocationsInFacility"] = new SelectList(locs, "ID", "Name", "DL");

Here is the view:

<label>Location in Facility</label>
<%= Html.DropDownList
        ("LocationsInFacility",(SelectList)ViewData["LocationsInFacility"]) %>

Here is the html output, I would have expected "DL" to be selected but it's not:

<select id="LocationsInFacility" name="LocationsInFacility">
<option value="">-- Select a Location in Facility --</option>
<option value="DL">DELI</option>
<option value="BK">BAKERY</option>
</select>

Why is "DL" not selected? What am I doing wrong?

A: 

Is DL a string in the LocationsInFacility data? You may need to pass the value in if not, rather than the ToString equivalent

Andrew Bullock
"DL" is the value for Deli. See the html above. Are you saying to pass in the word "Deli" instead?
Mike Roosa
see this http://ayende.com/Blog/archive/2008/11/11/and-yet-another-asp.net-mvc-bug.aspx
Andrew Bullock
+1  A: 

The solution is to change the Html.DropDownList to:

<%= Html.DropDownList("LocationsInFacility") %>
Mike Roosa