I have a single razor view in which i am trying to implement both Create and Edit options. Here is cshtml code for a drop down field:
@Html.DropDownListFor(model => model.StateID, (SelectList)ViewBag.StateID, "--Select--", new { @Id = "ddlState" })
However in edit mode although all the other fields are populated as per the model, the dropdown is not showing the saved selected value as per the model. I have used a viewbag to populate the dropdown and that works fine. The states are populated in the dropdown.
ViewBag.StateID = new SelectList(queryStatesInLookup, "LookupID", "LookupCode")
I debugged the razor page and checked. I get the state id from the model (for eg: 8), but this value wont bind to the dropdown. What gives? :/