带有自定义JSON Web服务器的Kendo UI Grid - “未捕获的TypeError:this.replace不是函数”

问题描述 投票:1回答:1

我有一个遗留的ASP.NET Web表单应用程序,它有一个Web服务来检索json中的数据。发送到此Web服务的数据也以json的形式发送。 Web服务实际上是一个aspx页面,它将数据作为已发布的表单数据获取:

json = Server.UrlDecode(Request.Form.ToString())

在Kendo-UI中,我传递的参数如下:

transport: {
    read: {
        url:  "MyService.aspx",
        dataType: "json",
        type: "POST",
        data: JSON.stringify(GetRequestParams())
    }
}

JSON.stringify(GetRequestParams())的值是

"{"Header":{"Method":"getfiles"},"Body":{"Data":{},"MaxResults":10,"PageNum":"1","FolderID":"14","SearchString":"","SearchSubFolders":false,"DepartmentID":"333333"},"ApiBaseUrl":"/Api3/"}"

但是,这会出现以下javascript错误:“未捕获TypeError:this.replace不是函数”如果我先传输数据而不先将其字符串化,则不会出现javascript错误,但在服务器端,而不是JSON ,我得到:

$inlinecount=allpages&Header[Method]=getfiles&Body[MaxResults]=10&Body[PageNum]=1&Body[FolderID]=14&Body[SearchString]=&Body[SearchSubFolders]=false&Body[DepartmentID]=333333&ApiBaseUrl=/Api3/&GetAjaxData=&$top=20

有没有人知道如何使用带有Kendo-UI的transport.read选项传递自定义数据对象,以便我可以解决服务器端的数据对象而没有问题?

或者以任何其他方式使用asp.net表单完成此任务的任何建议方式?

asp.net kendo-ui kendo-grid
1个回答
0
投票

我确实找到了解决方法,但不是100%,因为我最终没有剑道这样做。我从我的代码中看到的是:

传递数据:data: GetRequestParams()(没有stringify)

在后面的代码中我将确定这是否来自Kendo(VB.Net):

If (Request.Form("Header[Method]") IsNot Nothing AndAlso Request.Form("Header[Method]").ToLower() = "getfiles") Then
        KendoRequest = True
Else

而不是得到这样的参数:

If Request.Form("Body[PageNum]") IsNot Nothing Then
    PageNum = Convert.ToInt32(Request.Form("Body[PageNum]"))
End If

If Request.Form("Body[FolderID]") IsNot Nothing Then
    FolderID = Convert.ToInt32(Request.Form("Body[FolderID]"))
End If

不漂亮,但它奏效了。

© www.soinside.com 2019 - 2024. All rights reserved.