The Entertainment Shack

jQuery 1.4 param() and ASP.NET MVC3

Posted by Erik W on Nov 8, 2011 9:44 PM

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

Comments are disabled on this post.

Trackbacks are disabled on this post.