Html.DropDownList select value not given by model
I have a dropdown list like:
<%= Html.DropDownList("SoldTo", Model.SellDealerList, "Select a Dealer")%>
I am populating a list in my controller with the following code:
SellDealerList = new SelectList(repository.GetDealerList(), "id", "name", vehicle.SoldTo);
When I debug the code, the selected value in the SellDealerList has a value that gets set, but the HTML source does not display the selected value in the list.
I am puzzled as to what I am doing wrong, but being new to MVC I am pretty sure this is probably something very simple. The biggest difference from all the other Q&A I've seen is that I'm not using ViewData.
Thank!
source to share
Check my answer to this question, maybe it helps. Perhaps you have a "SoldTo" property in your Model, ViewData, or ModelState. DropDown tries to override the selected value if some of these objects have a property or key with the same name as your field. Is crazy if you don't know how it works internally because you can see that the selected property is set to true on the correct SelectList and no select option is selected yet.
source to share