ASP MVC TreeView的Kendo UI:代表Tree显示Json响应

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ASP MVC TreeView的Kendo UI:代表Tree显示Json响应相关的知识,希望对你有一定的参考价值。

我试图显示具有远程数据绑定的类别树。这是Controller方法:

    public JsonResult KendoTree(Guid? id)
    {
        var categoriesBO = _categoryManager.GetAllCategory().
            Where(c=> id==null ? c.ParentId==null : c.ParentId == id).
            Select(c=> new
            {
                id = c.Id,
                Name = c.Name,
                hasChildren = c.CategoryChilds.Any()
            });
        return Json(categoriesBO, JsonRequestBehavior.AllowGet);
    }

这是cshtml文件

    @{
    ViewBag.Title = "KendoTree";
}

    <h2>KendoTree</h2>

    @Html.Kendo().TreeView().Name("Categories").DataSource(dataSource => dataSource
        .Read(read => read.Action("KendoTree", "CategoryManagement")
    )).DataTextField("Name")

浏览器代表树显示Json结果(数组)。

我错过了什么吗?

答案

我明白了:我必须有一个Controller动作,它返回一个视图,然后从相关视图中调用kendo Html帮助器。

以上是关于ASP MVC TreeView的Kendo UI:代表Tree显示Json响应的主要内容,如果未能解决你的问题,请参考以下文章

使用 Kendo UI Asp.net mvc core 未显示图表组件

asp.net mvc kendo ui grid 加密列数据

带有 Asp.net MVC 的 Kendo UI 图表

用于 jquery CRUD 的 Asp.net core mvc + kendo ui

如何使用 ASP.NET MVC 在 Kendo UI Grid 中实现 N 级嵌套层次结构

Asp.Net MVC 应用程序的 Kendo UI 与 Jquery/Bootstrap 设计决策