This project is read-only.

Problem with MvcControlsToolkit_UpdateDropDownOptions

Aug 10, 2011 at 9:12 PM


I'm using "MvcControlsToolkit_UpdateDropDownOptions" to load a Dropdown with Ajax in a ThemedDataGridFor, but sometimes it don't work when I edit a line and it never work when I add more than 1 item.

This is happening in IE9 but not in Chrome.

If I add an "alert('test');" in the end of "MvcControlsToolkit_UpdateDropDownOptions" and the Dropdown is loaded.

Thank you

Aug 11, 2011 at 7:24 PM

Sure you gave to all dropdowns in all different rows a different name? Otherwise, the ajax call will have an ovalid target id (an id that is not unique)...Different browsers handle differently this situation....that is an error situation to be avoided.

Also if you try to generate manually different names for the exixying rows, how do you handle new rows?


The only way to be sure that each row has different names, us by using  id='@Html.PrefixedId("AName")' (or item..PrefixedId("AName") ). This way a "AName" will be automatically given a unique prefix that depends on the row. New created rows will have a different prefix.

Last thing. For the empty DropDown write <select......></select> and not <select....../> some browser have problems handly properly the las tag.

Let me know if this solve your problem.

However consider, that putting a different dropdown in each row may cause a lor of requests on the server.

Aug 12, 2011 at 12:15 PM

I uploaded my code to!174

Basically, first I edited the script "MvcControlsToolkit_UpdateDropDownOptions" to accept a new parameter to auto select a value in the list. I changed only this line:

items.push("<option value ='" + val + "' " + (currCss == null ? "" : "class = '" + currCss + "' ") + (val == selvalue ? "selected" : "") + ">" + text + "</option>");

In the helper "AjaxDropDownListHelper" I create an empty dropdown using "DropDownListFor" and then I create the script to populate the list. To get the id I use:

           string id = htmlHelper.PrefixedId(expression).EndsWith("_") ?
               htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId("") :

The code do the verification "EndsWith("_")" because if the "expression" is something like "m => m" (only with parameter) the "PrefixedId" don't return the right id. If I use "string id = htmlHelper.PrefixedId(expression);" to get the id, then it never works (neither to others dropdowns out of the grid or in Chrome).

I don't understand the reason of the dropdown works when I add "alert('test');" in the scripts end. Is possible that the Ajax request didn't have time to process the request and when I added the alert it works?

Aug 12, 2011 at 3:18 PM

To overcome the problem of the PrefixId use:


because htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId("")

  in some cases produce a different result. In the next version I will fix PrefixId;


Your code looks correct...adding alert....doesn't overcome any TimeOut problem since it just increases the computation time. Maybe, since, the server get several requests from different rows, it is not able to server them: introducing the alert just cause a delay between the calls, since javascript jait for the user to close the window.


WebDev is not an actual Internet is just to test programs in visual it get confused by several requests. Test your code on IIS, you can install it also on your dev machine. Just go into programs installations, and select to install pieces of windows.

Let me know if IIS solve the problem. Otherwise you can send a whole project so I can debug it.