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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.