views:

445

answers:

1

I have a drop down list like so:

<%= Html.DropDownList("SoldTo", Model.SellDealerList, "Select a Dealer")%>

I'm populating the list in my Controller with the following code:

SellDealerList = new SelectList(repository.GetDealerList(), "id", "name", vehicle.SoldTo);

When I debug through the code the selected value on the SellDealerList has a value that is being set but the HTML source shows no selected value in the list.

I'm baffled as to what I'm doing wrong, but being new to MVC I'm sure it is probably something very simple. The biggest difference from all the other questions and answers I've seen is that I'm not using the ViewData.

Thanks!

A: 

Check my answer to this question, maybe it helps. Perhaps you have a property "SoldTo" in your model, ViewData or ModelState. The DropDown tries to override the selected value if some of these objects has a property or key with the same name as your field. Is kind of crazy if you don't know how it works internally because you see the selected property set to true on the right item of the SelectList and yet no option of the select is selected.

Ariel Popovsky
Not sure what change but now the drop down list is populating correctly. Must have been a cache somewhere. Thanks for the help!
Jeff Giesbrecht