2014-12-02 59 views
0

我剛開始使用Kendo UI網格。我試圖讓它工作W/ASP.NET Web服務。Kendo UI Grid並未調用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 

我已經在webmethod中設置了斷點w /,但它們從未受到影響。我錯過了什麼?

+0

1.不需要kendo.web.min.js,它kendo.all.min.js被包圍。此外,打開你的開發工具或提琴手或其他東西,看看是否將Ajax請求發送到服務器。 – 2014-12-02 20:37:19

+0

感謝您的提示。它的狀態碼是500,這是很奇怪的,因爲其他服務工作正常。我在本地運行一切。 – user1147941 2014-12-02 21:05:30

+0

進入細節,錯誤消息是「無效的JSON原語:採取。」 – user1147941 2014-12-02 21:14:25

回答

0

所以我現在就開始工作了。把它磨練成缺乏經驗。我不得不修改傳輸值和web方法。這裏是工作代碼:

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

和Web方法:

<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