【问题标题】:using jsTree with MVC .net将 jsTree 与 MVC .net 一起使用
【发布时间】:2012-06-02 15:59:16
【问题描述】:

我有一个 MVC 项目,我试图在控制器对象中调用一个方法,但该方法没有被调用,这是代码。

.NET

Namespace WindowTreeView
Public Class DefaultController
    Inherits System.Web.Mvc.Controller

    '
    ' GET: /Default

    Function Index() As ActionResult
        Return View()
    End Function


    Function GetTreeNodes() As JsonResult



    End Function


End Class
End Namespace

JQUERY

$(document).ready(function () {

$("#divJsTreeDemo").tree({
    data: {
        method: "POST",
        dataType: "json",
        url: "Default/GetTreeNodes",
        async: true,
        contentType: "application/json; charset=utf-8",
        data : "{}"
    }
});
});

【问题讨论】:

  • 网址似乎错误。尝试这个。 url: "/Default/GetTreeNodes",
  • 在您的数据中,将method: "POST" 更改为type: "POST"
  • @Priyank Patel,感谢您的回复,但这没有用,但从现在开始就不能使用这个网址了。
  • 你在global.asax中定义了路径吗?
  • @mazhar kaunain baig,不,我没有这是必须的,因为我读过的文章没有提到这个

标签: jquery asp.net-mvc json


【解决方案1】:

由于您要请求数据,请尝试 GET 请求 - 不要发布!

method: "POST"

然后你可以返回你的JSON结果并在js中解析。

【讨论】:

    【解决方案2】:

    我基本上是从他们的网站上复制的(查看last sample(PHP 和 mySQL 演示 + 事件顺序)),然后启动并运行。稍微修改了粘贴的示例。

       $(function () {
            $("#demo")
                .jstree({
                    "plugins": ["..."],
                    "json_data": {
                        "ajax": {
                            "url": '@Url.Action("GetChildren")',
                            "data": function (n) {
                                return {
                                    "id": n.attr ? n.attr("id") : -1
                                };
                            }
                        }
                    },  
                });
        }
    

    但这也许不是你的问题... $("#divJsTreeDemo").tree({

    【讨论】:

      猜你喜欢
      • 2016-11-13
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 2011-02-25
      • 1970-01-01
      相关资源
      最近更新 更多