I got this line of code:
<%=Html.DropDownList("Status",(SelectListItem[])ViewData["statusList"], new {@style = "width: 190px"})%>
The dropdown is always populated with the data from ViewData which is good but i want to be selected the value corresponding to the Model.Status property.
What am i doing wrong?
When you create the SelectList (this is done in the Model or Controller (not recommended but it’d be fine), NOT in the view) you can just pass the selected item in the constructor and it will take care for the rest:
Then you don’t have to cast the list from the ViewData to a SelectListItem but to a SelectList. This is the only line that should appear in your view.