hijiki7777
asked on
ASP.Net MVC 2 setting a DropDownListFor item
I am new to MVC and I am starting at version 2. I am populating a View with a row of data that contains an Id field (Status). This Id field is bound to a list of Status strings displayed in a drop down list. In my controller I populate a SelectList collection in which the current Status is correctly selected (I checked this). However the View always selects the first item on the list regardless. So what is wrong with this?
<div class="editor-field">
<%: Html.DropDownListFor(model => model.Status, ViewData["Status"] as IEnumerable<SelectListItem>)%>
<%: Html.ValidationMessageFor(model => model.Status) %>
</div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Spot on.
I think I should use the View Model from now on.
I think I should use the View Model from now on.
If you look at most ASP.NET MVC best practice recommendations they advise using the Model rather than using magic strings which are error prone.
http://stackoverflow.com/questions/624828/asp-net-mvc-html-dropdownlist-selectedvalue
Arun