telerik treeview asp.net mvc - 链接不适用于非根节点

发布于 2024-11-26 09:25:45 字数 1119 浏览 5 评论 0原文

在我看来,我正在使用这段代码:

@(Html.Telerik().TreeView()
.Name("AjaxTreeView")
.BindTo(Model, (item, category) =>
{
    // bind initial data - can be omitted if there is none
    item.Text = category.Name;
    item.Action("Details", "Categories", new { Id = category.Id });
    item.Value = category.Id.ToString();
    item.LoadOnDemand = category.NOChildren > 0;
})
.DataBinding(dataBinding => dataBinding
        .Ajax().Select("_TreeViewAjaxLoading", "Categories")
)
)

它工作正常(ajaxified展开和折叠)。操作链接工作正常,但仅适用于根节点。我当前的控制器为 ajax 加载输出 JSON:

[Transaction]
[HttpPost]
public ActionResult _TreeViewAjaxLoading(TreeViewItem node)
{
    int? ParentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

    var nodes = from item in CategoryRepository.GetChildren(ParentId)
        select new TreeViewItem
        {
            Text = item.Name,
            Value = item.Id.ToString(),
            LoadOnDemand = item.NOChildren > 0
        };
    return new JsonResult { Data = nodes };
}

未设置操作链接。我如何在这里设置操作链接?谢谢。

基督教

I am using this code in my view:

@(Html.Telerik().TreeView()
.Name("AjaxTreeView")
.BindTo(Model, (item, category) =>
{
    // bind initial data - can be omitted if there is none
    item.Text = category.Name;
    item.Action("Details", "Categories", new { Id = category.Id });
    item.Value = category.Id.ToString();
    item.LoadOnDemand = category.NOChildren > 0;
})
.DataBinding(dataBinding => dataBinding
        .Ajax().Select("_TreeViewAjaxLoading", "Categories")
)
)

It works fine (ajaxified expand and collapse). The action links work fine but only for the root nodes. My current controller that spews out JSON for the ajax load:

[Transaction]
[HttpPost]
public ActionResult _TreeViewAjaxLoading(TreeViewItem node)
{
    int? ParentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

    var nodes = from item in CategoryRepository.GetChildren(ParentId)
        select new TreeViewItem
        {
            Text = item.Name,
            Value = item.Id.ToString(),
            LoadOnDemand = item.NOChildren > 0
        };
    return new JsonResult { Data = nodes };
}

does not set the action link. How can I set the action link here? Thanks.

Christian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮世清欢 2024-12-03 09:25:45

这似乎可以解决问题:

[Transaction]
[HttpPost]
public ActionResult _TreeViewAjaxLoading(TreeViewItem node)
{
    int? ParentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

    UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext);
    var nodes = from item in CategoryRepository.GetChildren(ParentId)
        select new TreeViewItem
        {
            Text = item.Name,
            Value = item.Id.ToString(),
            LoadOnDemand = item.NOChildren > 0,
            Url =  u.Action("Details", "Categories", new { Id = item.Id} )
        };
    return new JsonResult { Data = nodes };
}

This seems to do the trick:

[Transaction]
[HttpPost]
public ActionResult _TreeViewAjaxLoading(TreeViewItem node)
{
    int? ParentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

    UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext);
    var nodes = from item in CategoryRepository.GetChildren(ParentId)
        select new TreeViewItem
        {
            Text = item.Name,
            Value = item.Id.ToString(),
            LoadOnDemand = item.NOChildren > 0,
            Url =  u.Action("Details", "Categories", new { Id = item.Id} )
        };
    return new JsonResult { Data = nodes };
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文