我正在尝试将参数从 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/