0

Please consider the following line of code in an MVC5 EF6 project:

 @Html.DropDownListFor(g => ssi[0].property1, new SelectList(dd, "value", "text"), ssi[0].property1)

The issue I have is that when the page loads, the correct selection is displayed in the drop down based on the model.property returned from the database. However, when saving using @Ajax.BeginForm, unless I change the value in the drop down which is not always required, the original value does not get saved. Instead a null is recorded and drop downs revert to unbound state in terms of their selected values.

My question is how do I ensure the original selected value loaded in the dropdown is saved back without touching the drop down?

Thanks

Mat Safe
  • 31
  • 4

1 Answers1

0

Having looked at another MVC - Set selected value of SelectList, the issue was that I was using a selectList in my model. (dd). Having read the other answer I have realised the SelectList should not have been in my model as it is a UI element, instead I should have used a simple "text" "value" model as the collection in the statement. I already had this in my model so I removed the SelectList and bound dd to the "text" "value" collection. This fixed the issue. Apologies if I've wasted anybody's time.

Mat Safe
  • 31
  • 4