NET MVC 1.0.
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.
我将选定的值DeptID作为第四个参数传递,但它不起作用。当我调试时,上面的选择列表与所选值是正确的。
I use
<%= Html.DropDownList("DeptID", (SelectList)ViewData["DeptID"]) %>
in the view.
在视图中。
2 个解决方案
#1
#2
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.
要检查一件事,第1和第4个参数(DeptID和course.DeptID)是什么类型的?这些将需要兼容 - 例如如果DeptID是字符串的集合,那么course.DeptID将需要是一个字符串。
#1
#2
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.
要检查一件事,第1和第4个参数(DeptID和course.DeptID)是什么类型的?这些将需要兼容 - 例如如果DeptID是字符串的集合,那么course.DeptID将需要是一个字符串。