剑道 UI 网格不调用 ASP.NET Web 服务

Kendo UI Grid not calling ASP.NET web service

本文关键字:NET Web 服务 ASP 调用 UI 网格 剑道      更新时间:2023-09-26

我刚开始使用剑道UI网格。 我正在尝试让它与 ASP.NET Web 服务一起工作。

这是我必须创建网格的 js:

$("#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())
});

这是 Web 方法的代码(显然只是测试一下):

<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

我还引用了该页面:

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

我已经在网络方法中设置了断点,但它们永远不会被命中。 我错过了什么?

所以我现在让它工作了。 归咎于缺乏经验。

我不得不修改传输值和 Web 方法。 这是工作代码:

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

和网络方法:

<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