This is a migrated thread and some comments may be shown as answers.

Save/Update using WebMethods example

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 23 Oct 2012, 01:32 AM
I am having trouble getting the grid save function to work with a WebMethod. The short version of the code:


       transport: {
                :
                :
                    update: {
                        url: crudServiceBaseUrl + "/Update",
                        contentType: 'application/json; charset=utf-8',
                        dataType: "json",
                        type: 'POST'
                    },
                    parameterMap: function (data, operation)
                    {
                        if (operation !== "read" && data.models)
                        {
                            return JSON.stringify({ JSONparam: data.models });
                        }
                    }

     

My server side code:

       [WebMethod()]
        static List<bool> Update(string JSONparam)
        {
            List<bool> boolList = new List<bool>();
                   :
                   :
            return boolList;
        }


The server side code is never called. What should the "update" section of the transport look like? I probably have it wrong.

1 Answer, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 01 Nov 2012, 07:17 PM
I figured out part of this problem, with assistance from this post:

http://stackoverflow.com/questions/1087928/passing-complex-json-string-to-1-parameter-webmethod-in-c-sharp-desearialize-i

Modifying the parameter map function as follows fixed parameter problem, so now my web method is called:

 parameterMap: function (data, operation)
                    {
                        if (operation !== "read" && data.models)
                        {
                            return JSON.stringify({ JSONparam:JSON.stringify(data.models) } );
                        }
                    }

But now the serialized JSON includes the __type property, which is causing problems with the .Net deserializer:

The JSON string:
"[{\"__type\":\"My.Namespace.MyObject\",\"Age\":23,\"Lastname\":\"Smith\",\"firstname\":\"Joe\"}]"

I have read a few links about this, but have not found a solution.


Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or