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?
Found the Answer
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With