views:

2820

answers:

2

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?

+4  A: 

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.

Craig Stuntz
contactId is a Guid encoded into a string, when I have string contactId in the signature I get the following string value : "[object HTMLInputElement]".I presume I need to get the value of the jQuery('#contactId') element rather than the element itself. Unfortunately I am completely new to jQuery/JavaScript and don't know how to do that!
Colin Desmond
Got it! Need to have postData: {contactId : jQuery('#contactId').val()} to get the string representation of the Guid. Many thanks.
Colin Desmond
You can change string -> Guid and MVC binding will convert it for you.
Craig Stuntz
A: 

Hii, My requirement is: I have a search form with few textboxes and search button. On hitting the search button, results should be populated in the grid. I have used "postData" option and it worked very much! Thanks a ton!!