c# - jsTree 3.0.2 - 如何将参数传递给 aspx webmethod

标签 c# asp.net web-services jstree

我正在尝试将参数从 jsTree 3.0.2 传递到 aspx 页面上的 Web 方法,但它没有访问 Web 方法。但是,当没有参数时它确实有效。谁能指出我方法的错误?

带参数(不工作):

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll(string id)
{
    // method does not get called
}

$("#jsTreeTest").jstree({
    "core": {
        "data": {
            "url": "MyPage.aspx/GetAll",
            "type": 'POST',
            "dataType": 'JSON',
            "contentType": 'application/json;',
            'data': function (node) {
                return { 'id': "01" };
            }
        }
    }
});

无参数(工作):

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll()
{
    // successfully calls method
}

$("#jsTreeTest").jstree({
    "core": {
        "data": {
            "url": "MyPage.aspx/GetAll",
            "type": 'POST',
            "dataType": 'JSON',
            "contentType": 'application/json;',
            "data": function (node) { return {}; }
        }
    }
});

谢谢。

最佳答案

发现问题。应该是:

return '{ "id" : "01" }';

工作代码:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll(string id)
{
    // success!
}

$("#jsTreeTest").jstree({
    "core": {
        "data": {
            "url": "MyPage.aspx/GetAll",
            "type": 'POST',
            "dataType": 'JSON',
            "contentType": 'application/json;',
            "data": function (node) {
                return '{ "id" : "01" }';
            }
        }
    }
});

关于c# - jsTree 3.0.2 - 如何将参数传递给 aspx webmethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24934223/

相关文章:

c# - WCF 服务库项目找不到对其他项目的引用

c# - 在 Sharepoint 中下载文件后不再回发

java - 如何提供自己的Web服务实现实例?

java - 无法使用从浏览器发布的 Base 64 编码字符串创建图像

asp.net - 将 Microsoft.Practices.EnterpriseLibrary.Caching 与 ASP.NET 一起使用是否合适?

c# - 如何在 Visual Studio 中测试 API 服务

c# - 为什么我不能使用以下 IEnumerable<string>?

C# 编译器缺陷? : Not detecting methods that always throw exceptions

c# - 为什么我从 Web 应用程序而不是控制台应用程序收到无法连接到远程服务器异常?

c# - 如何使用c#在tfs 2012中获取保存的查询