ASP.net MVC DropDownList的pre-选择的项目被忽略 [英] ASP.net MVC DropDownList Pre-Selected item ignored
问题描述
我现在面临一个问题simular如问题<一个概述href=\"http://stackoverflow.com/questions/589935/html-dropdownlist-in-asp-net-mvc-rc-refresh-not-$p$p-selecting-item\">\"Html.DropDownList在ASP.NET MVC RC(刷新)未pre-选择项
I am facing a simular problem as outlined in the question "Html.DropDownList in ASP.NET MVC RC (refresh) not pre-selecting item"
我使用ASP.net MVC 1.0,需要时DropDownList的改变相关的JavaScript调用。
I'm using ASP.net MVC 1.0 and need to associated a javascript call when the DropDownList is changed.
<%=Html.DropDownList("SelectList",
(SelectList)ViewData["SelectList"],
new { onchange="javascript:selected_droplist();" } )%>
这是除的这是无视我的pre-选择的项目的
如果我删除多余的功能:
If I remove the extra functionality:
<%=Html.DropDownList("SelectList")%>
有快乐,会用我的pre-选择的项目。的,但我不明白的JavaScript操作!的
It is happy and will use my pre-selected item. BUT i don't get the Javascript action!
那么,如何将JavaScript添加到onchange事件?
推荐答案
当给控制的名称(在此情况下,第一个参数是的SelectList)
是一样的密钥中ViewData字典中的一个基本上是螺丝并在选择列表的忽略$ P $对选择的项目
When the Name given to the control (the first parameter in this case being "SelectList") is the same as one of the Keys in the ViewData dictionary basically it screws up and ignores the pre-selected item in the SelectList
只需重命名的DropDownList它正常工作,并结合到pre-选择的项目
By simply renaming the DropDownList it works correctly and binds to the Pre-Selected item
这篇关于ASP.net MVC DropDownList的pre-选择的项目被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!