I have MVC3 website with edit form. On this form there is DropDownList that shows list of values that can be chosen. I want it to be set at previously selected value(on create form). This value is in Model.Status. I thought that this code would work:
@Html.DropDownList("Status",
new SelectList(ViewBag.Status as System.Collections.IEnumerable, "Id", "Status", Model.Status))
But the DropDownList is always set on first value from the list. I have checked – the correct value is in Model.Status.
Value of Model.Status is an id of status from list. ViewBag.Status is a list with id and string description – Status.
How to make it show the right value?
Any help much appreciated!
Have you checked this bug
Avoid to use same name of
DropDownListandSelectList.