NovoGeek's Blog (Archive)

Technical insights of a web geek

Customizing jQuery plugins for "d parameter" in .NET 3.5 JSON response.

I was trying to use jqGrid, an excellent jQuery based grid, for building a zero postback page. It's configuration is very simple, similar to flexigrid, but has many additional features like inline editing, subgrids etc.

What jqGrid expects is a JSON response having few objects and arrays, which are mapped to columns in the grid inside the grid.base.js file, like this.

Though the grid's AJAX call is successful, data is not being bound to thegrid. The reason is, .NET 3.5 returns JSON object which is prefixed with a "d" parameter like this.

So, to map the JSON data to the grid, we have to manually parse the AJAX response and separate the "d" parameter in AJAX success callback. This applies not only to jqGrid, but also to all jQuery plugins which expect JSON response.

I was about to write more on why .Net 3.5 prefixes "d" to JSON response, how it enhances security and how to parse it easily., but incidentally, Dave ward explained the concept excellently in his latest article: http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again

So no more worrying about .Net's "d" again :)

Comments (2) -

  • Sam

    7/27/2009 9:18:44 AM |

    Hi,
    I've been struggling for a really long time to use Jqgrid along with Jayrock.

    I'm trying to convert a datatable to JSON using Jayrock and then pass it on to Jqgrid.... But,it doesn't work.

    From your post,I'm beginning to understand that Jqgrid requires JSON in a specific format.

    How do I get this thing to work?

    Please help me if possible..
    Thanks.

  • Sam

    7/27/2009 9:23:40 AM |

    I've seen your other post that tells how to use Jayrock.

    But now,I want to be able to smoothly use a DataTable through Jayrock to Jqgrid.

    Is this possible? Can you help me with it?

    Thanks

Comments are closed