Reputation: 24332
NET MVC 1.0.
I use
ViewData["DeptID"] = new SelectList(DeptID, "ID", "Name", course.DeptID);
where I am passing the selected value DeptID
as forth parameter, but it doesn't work. When I debug, then the above selection list is correct with the selected value.
I use
<%= Html.DropDownList("DeptID", (SelectList)ViewData["DeptID"]) %>
in the view.
Upvotes: 0
Views: 240
Reputation: 8511
When you say "If i do debug then also above Selection list is correct with selected value", are you saying this works in debug mode but does not work in release, or are you saying that you see the correct value in the 4th parameter but it still does not appear to selct the item in the list?
One thing to check, what types are the 1st and 4th parameters (DeptID
and course.DeptID
)? These will need to be compatible - e.g. if DeptID
is a collection of strings then course.DeptID
will need to be a string.
Upvotes: 0
Reputation: 4802
Try just using:
<%= Html.DropDownList("DeptID") %>
Here is an article about it.
Upvotes: 1