REQUEST A DEMO

jQuery 1.4 breaks ASP.Net MVC actions with array parameters

We had a Ajax-ified page break on us today and eventually figured out that the cause was related to an upgrade of jQuery and in particular a change in how jQuery 1.4 does serialization of array parameters for Ajax operations. From the jQuery 1.4 Release Notes.

jQuery 1.4 adds support for nested param serialization in jQuery.param, using the approach popularized by PHP, and supported by Ruby on Rails. For instance, {foo: ["bar", "baz"]} will be serialized as “foo[]=bar&foo[]=baz”.

In jQuery 1.3, {foo: ["bar", "baz"]} was serialized as “foo=bar&foo=baz”. However, there was no way to encode a single-element Array using this approach. If you need the old behavior, you can turn it back on by setting the traditional Ajax setting (globally via jQuery.ajaxSettings.traditional or on a case-by-case basis via the traditional flag).

Our page was using getJSON to get data back from an ASP.Net MVC action that looks like this

public JsonResult GetListElements(string listTitle, string[] levelValues)

We found that the second array parameter would always be null. Adding the recommended Ajax setting for the page corrected the issue.

// Enables for all serialization
jQuery.ajaxSettings.traditional = true;

For more details about this issue check out this post: jQuery 1.4 breaks ASP.NET MVC parameter posting.