ASP.net MVC DropDownList已预选项目被忽略 [英] ASP.net MVC DropDownList Pre-Selected item ignored
问题描述
我正面临一个模拟问题,如问题Html.DropDownList在ASP.NET MVC RC(刷新)不预选项目
我正在使用ASP。 net MVC 1.0,当DropDownList被更改时需要关联一个javascript调用。
<%= Html.DropDownList(SelectList ,
(SelectList)ViewData [SelectList],
new {onchange =javascript:selected_droplist();})%>
这一切都很好,除了它忽略了我预选的项目 / p>
如果我删除了额外的功能:
<%= Html .DropDownList( 的SelectList)%>
很高兴,会使用我预选的项目。
那么,如何将javascript添加到onchange事件? strong>
当给予控件的名称(在这种情况下的第一个参数是SelectList)
与ViewData字典中的一个键基本相同,基本上它会拧紧并忽略SelectList中的预先选择的项目
只需重命名DropDownList即可正确并绑定到预选项目
I am facing a simular problem as outlined in the question "Html.DropDownList in ASP.NET MVC RC (refresh) not pre-selecting item"
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();" } )%>
This is all good except it is ignoring my pre-selected item
If I remove the extra functionality:
<%=Html.DropDownList("SelectList")%>
It is happy and will use my pre-selected item. BUT i don't get the Javascript action!
So, how do i add the javascript to the onchange event?
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
By simply renaming the DropDownList it works correctly and binds to the Pre-Selected item
这篇关于ASP.net MVC DropDownList已预选项目被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!