简体   繁体   中英

Kendo UI Grid not calling ASP.NET web service

I just started working with the Kendo UI grid. I'm trying to get it to work w/ an ASP.NET web service.

Here's the js I have to create the grid:

$("#grid").kendoGrid({
    pageable: true,
    dataSource: {
        serverPaging: true,
        schema: { data: "d.Records", total: "d.total" },
        pageSize: 10,
        type: "json",
        transport: {
            read: {
                url: "/services/Records.asmx/GetRecords",
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset-utf-8" 
            }
        }
    },
    rowTemplate: kendo.template($("#kendoTmpl").html())
});

Here's the code for the web method (just testing things out obviously):

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function GetRecords() As RecordList
    Dim x as List(Of Record) = New List(Of Record)
    Dim total as Integer = 25

    Dim skipVal as Integer = Convert.ToInt32(HttpContext.Current.Request.QueryString("skip"))
    Dim takeVal as Integer = Convert.ToInt32(HttpContext.Current.Request.QueryString("take"))

    For i as Integer to total
        'Record class has ID and Detail properties
        x.Add(new Record(i, "This is Record #" + i.ToString()))
    Next

    'RecordList has Total and Records properties
    Return New RecordList(total, x)
End Sub

I have also referenced w/ the page:

jquery.min.js //jQuery v1.9.1
kendo.all.min.js
kendo.web.min.js

I've set up breakpoints w/in the webmethod, but they never get hit. What am I missing?

So I got it working now. Chalk it up to inexperience.

I had to modify the transport values and the web method. Here is the working code:

...
transport: {
        read: {
            url: "/services/Records.asmx/GetRecords",
            type: "POST",
            contentType: "application/json; charset=utf-8"
        },
    parameterMap: function(data) {
        return JSON.stringify(data);
    }
}
...

And the web method:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function GetRecords(ByVal skip as Integer, ByVal take as Integer) As RecordList
    Dim x as List(Of Record) = New List(Of Record)
    Dim total as Integer = 25

    For i as Integer to total
        'Record class has ID and Detail properties
        x.Add(new Record(i, "This is Record #" + i.ToString()))
    Next

    'RecordList has Total and Records properties
    Return New RecordList(total, x.Skip(skip).Take(take).ToList())
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM