Colin Desmond
Colin Desmond

Reputation: 4854

Using jqGrid userdata

I have a jqGrid on an ASP.Net MVC view. I want to use to pass the value of a hidden text control on the page as an additional parameter to a jqGrid method.

I have the following hidden text field:

<div>
<%= Html.Hidden("contactId", Model.ContactId) %>
</div>

and I want to do something like:

userdata: {contactId : jQuery('#contactId')}

in the jqGrid call. The Controller Action method has the following signature:

public ActionResult SearchResult(string sidx, string sord, int page, int rows, object userdata)

But when I run it, userdata in the C# code just says System.Object when I inspect it in the debugger, and I don't think I can get anythings useful out of it.

Any ideas where I have gone wrong?

Upvotes: 6

Views: 8112

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126547

The jqGrid property you want is postData. UserData goes the other way.

Change your call to JqGrid to include:

postData: {contactId : jQuery('#contactId').val()}

Then change the signature of your action to take a contactId:

public ActionResult SearchResult(string sidx, string sord, int page, int rows, 
    int contactId)

I guessed at the type. Use the real type in place of int.

Upvotes: 6

Related Questions