Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Post To .NET WebMethod ScriptMethod throws Javascript error

$
0
0
Hi,

I'm trying to fetch some json data from a .NET WebMethod (ScriptMethod) via a HTTP POST using a kendo.data.DataSource.

I was able to trigger the .NET WebMethod and json data is returned.

However, a javascript error "Uncaught TypeError: e.slice is not a function" ​is thrown by "kendo.all.min.js:11" on the client side.

Not sure what is wrong.


The javascript code is as follows:

           var param = { ID: 1, SearchString: "some string" };

            var dataSourceEntities = new kendo.data.DataSource({
                transport: {
                    read: {
                        type: "POST",
                        url: app.apiUrl + "/GetEntities",
                        contentType: "application/json; charset=utf-8",
                        dataType: 'json'
                    },
                    parameterMap: function(options, operation) {
                        return JSON.stringify(param);
                    },
                    schema: {
                        data: "d.Data", // ASMX services return JSON in the following format { "d": <result> }. Specify how to get the result.
                        total: "d.Total",
                        model: { // define the model of the data source. Required for validation and property types.
                            id: "SelectOptionVM",
                            fields: {
                                text: { type: "number" },
                                value: { type: "string" },
                                selected: { type: "boolean" }
                            }
                        }
                    }
                }
            }).read();


The .NET WebMethod code is as follows:

        [System.Web.Services.WebMethod(EnableSession = true)]
        [System.Web.Script.Services.ScriptMethod]
        public static DataSourceResult GetEntities(int ID, string SearchString)
        {
            List<SelectOptionVM> result = new List<SelectOptionVM>();

            List<TestEntity> tes =
                ProctorSessions
                .Select(ts => ts.Location.Entity)
                .Distinct()
                .OrderBy(te => te.Name).ToList();

            foreach (TestEntity te in tes)
            {
                result.Add(new SelectOptionVM() { text = te.Name, value = te.TestEntityId.ToString() });
            }

            return result.AsQueryable().ToDataSourceResult(int.MaxValue, 0, null, null);
        }

 

The JSON data returned (captured on Fiddler) is as follows:

{"d":{"__type":"Zoomorphix.Kendo.Extensions.DataSourceResult","Data":[{"__type":"ExamStudioPortal.Proctor.Dashboard4+SelectOptionVM","text":"Entity 1","value":"1","selected":false},{"__type":"ExamStudioPortal.Proctor.Dashboard4+SelectOptionVM","text":"Entity 2","value":"2","selected":false},{"__type":"ExamStudioPortal.Proctor.Dashboard4+SelectOptionVM","text":"Entity 3","value":"3","selected":false}],"Total":3}}

Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>