如何使用 MVC 通过 Ajax 加载 Dynatree
请有人帮忙。 我无法弄清楚如何从服务器加载 Dynatree。 我没有得到一棵树,而是得到“加载错误!(错误)” 我已经阅读了文档的每个部分,并阅读了数百个 stackoverflow 类型的答案,但仍然不明白,所以我希望有人能告诉我该怎么做。
这就是我所拥有的:
VIEW
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>LoadAjax</title>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.16.js" type="text/javascript"></script>
<script src='../../Scripts/jquery.cookie.js' type="text/javascript"></script>
<link rel='stylesheet' type='text/css' href='../../Content/skin/ui.dynatree.css' />
<script src='../../Scripts/jquery.dynatree.js' type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
initAjax: { url: "/LoadAjax/GetNodes" }
});
});
</script>
</head>
<body>
<div id="tree"></div>
</body>
</html>
CONTROLLER
public ActionResult GetNodes()
{
var n1 = new DynaNode { title = "Node 1", key = "k1", isLazy = false };
var n2 = new DynaNode { title = "Node 2", key = "k2", isLazy = false };
var n3 = new DynaNode { title = "Node 3", key = "k3", isLazy = false };
var nodeArray = new List<DynaNode> {n1, n2, n3};
return Json(nodeArray);
}
CLASS
public class DynaNode
{
public string title { get; set; }
public bool isFolder { get; set; }
public bool isLazy { get; set; }
public string key { get; set; }
}
Please someone help.
I cannot work out how to load a Dynatree from the server.
Instead of getting a tree I get "Load error! (error)"
I have read every single part of the documentaion and read hundreds of stackoverflow type answers and still do not understand, so I am hoping someone will just tell me what to do.
This is what I have:
VIEW
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>LoadAjax</title>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.16.js" type="text/javascript"></script>
<script src='../../Scripts/jquery.cookie.js' type="text/javascript"></script>
<link rel='stylesheet' type='text/css' href='../../Content/skin/ui.dynatree.css' />
<script src='../../Scripts/jquery.dynatree.js' type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
initAjax: { url: "/LoadAjax/GetNodes" }
});
});
</script>
</head>
<body>
<div id="tree"></div>
</body>
</html>
CONTROLLER
public ActionResult GetNodes()
{
var n1 = new DynaNode { title = "Node 1", key = "k1", isLazy = false };
var n2 = new DynaNode { title = "Node 2", key = "k2", isLazy = false };
var n3 = new DynaNode { title = "Node 3", key = "k3", isLazy = false };
var nodeArray = new List<DynaNode> {n1, n2, n3};
return Json(nodeArray);
}
CLASS
public class DynaNode
{
public string title { get; set; }
public bool isFolder { get; set; }
public bool isLazy { get; set; }
public string key { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我发现问题了。我很尴尬地承认这是一个初学者的错误。
查看
控制器
Ok, I found the problem. I am embarrased to admit that it was a beginner's mistake.
VIEW
CONTROLLER
请运行此解决方案:
Run this solution, please: