tags:

views:

135

answers:

2

Hi I am using ASP.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.

+1  A: 

Try just using:

<%= Html.DropDownList("DeptID") %>

Here is an article about it.

Mike Roosa
A: 

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.

Steve Haigh
Vikas
ok now it is working as Mike Roosa said
Vikas