0

We're using ASP.NET Webforms and jqGrid. I have no problem retrieving data from our webservice to the grid. However, when trying to use saveRow, we get an exception. I'm thinking it's due to invalid json, but using the built in saveRow() I would have guessed that the grid would make it valid json. Using fiddler2 and the call uses "application/json; charset=utf-8"

Calling saveRow:

$("#SupplierSettingTable").jqGrid('saveRow', rowNumber, true, '<%= ResolveClientUrl("~/Services/SupplierSettingService.asmx/SetSupplierSettingItem")%>' );

Here is the exception:

{"Message":"Invalid JSON primitive: AccountGroupName.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}

Help appreciated...

Lars Thorén
  • 453
  • 2
  • 7
  • 22

1 Answers1

1

You should verify that you use

ajaxRowOptions: { contentType: "application/json" }

and

serializeRowData: function (data) { return JSON.stringify(data); }

jqGrid parameters. See this and this answers for details.

If it will not help you should include in your question the exact data which will be send to the server and the response. You will get the information with respect of Fiddler of Firebug.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, we were missing "serializeRowData: function (data) { return return JSON.stringify(data); }" in our grid. – Lars Thorén Jun 10 '11 at 09:10
  • I was a bit quick there. While the error went away data is now never passed on to the server side. Any idea why this might be? However if I do an alert of JSON.stringify(data) in serializeRowData it outputs the correct value. – Lars Thorén Jun 10 '11 at 09:48
  • @Lars: Could you inspect the data which will be send to the server in Fiddler of Firebug? What the data exactly will be send and which prototype has the backend webmethod? Do you set all parameters of the webmethod? All parameters must be set at least to `null`. – Oleg Jun 10 '11 at 09:52
  • @Oleg: The only thing sent is: {"d":""}, In your original answer you had 2 returns, I assume that was an error and I removed one of them. The Webmethod is completely empty with no parameters for the time being. – Lars Thorén Jun 10 '11 at 09:57
  • @Lars: Thanks, I removed the second return. The answer `{"d":""}` from the server is correct, but what are sent to the server in the request? The answer `{"d":""}` shows indirect that the web method was called and it return an empty result. Do use use `editurl` parameter of jqGrid by the way or the main `url` do all the work? – Oleg Jun 10 '11 at 10:07
  • @Lars: Probably [the answer](http://stackoverflow.com/questions/3917102/jqgrid-add-row-and-send-data-to-webservice-for-insert/3918615#3918615) could help you. – Oleg Jun 10 '11 at 10:12
  • @Oleg: It was correct the whole time, just an error on my part as for specifying the input parameters. – Lars Thorén Jun 10 '11 at 11:27
  • @Lars: Nevertheless, if the problem still exist I could try to help you if you post two additional informations: the data which will be posted to the server and the signatur (prototype with all parameters) of the web method which will be called. – Oleg Jun 10 '11 at 11:34