The Entertainment Shack

Nov 8 '11

jQuery 1.4 param() and ASP.NET MVC3

I recently upgraded a ASP.NET MVC3 project from jQuery 1.3 to 1.4 that was using jQuery's $.param() function to build a query string from an object.

After this upgrade however, everything broke. All the values were coming back as null in the controller actions.

It turns out jQuery changed the way it serializes query strings in order to support the latest versions of PHP and Ruby on Rails. This, however, broke ASP.NET MVC3.

// jQuery 1.3
// Returns test.php?a=1&a=2&a=3
$('#test').load('test.php', {
  a: [ 1, 2, 3 ]
// jQuery 1.4
// Returns test.php?a[]=1&a[]=2&a[]=3
$('#test').load('test.php', {
  a: [ 1, 2, 3 ]

Luckily, the fix is easy. You don't get the new nesested parameter functionality in jQuery 1.4+, but it's not like it would have worked with ASP.NET MVC3 anyway:

$.ajaxSetup({ traditional: true });

More on this.

listed in:, jquery, mvc |