我有一个遗留的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表单完成此任务的任何建议方式?
答案 0 :(得分:0)
我确实找到了一个工作,但不是100%的工作,因为我最终没有剑道这样做。我从我的代码中看到的是:
传递数据:data: GetRequestParams()
(不带字符串)
在后面的代码中,我将确定这是否来自剑道(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
不漂亮,但有效。