asp.net-mvc - Kendo UI Treeview 绑定(bind)

标签 asp.net-mvc data-binding binding kendo-ui kendo-treeview

我想做 Kendo TreeView显示第一次加载时的所有节点。我正在使用 Kendo 'Binding to remote data' 示例,但它不能正常工作。它只显示第一级,传递给 Controller ​​操作的 id 始终为空。
请帮我。

查看代码:

@(Html.Kendo().TreeView()
    .Name("treeview")
    .DataTextField("Title")
    .ExpandAll(true)
    .LoadOnDemand(false)
    .DataSource(dataSource => dataSource
    .Read(read => read.Action("Employees", "Follow").Data("addData"))))

 function addData(data) {
    return { id: data.id };
}

Controller 代码: ( Controller Follow)
public System.Web.Mvc.JsonResult Employees(int? id)
{
    System.Collections.Generic.List<FollowType> List =
        new System.Collections.Generic.List<FollowType>();

    if (id.HasValue == true) {
        List = FollowTypeList.FindAll(current => current.ParentId == id);
    } else {
        List = FollowTypeList.FindAll(current => current.ParentId == null);
    }

    System.Collections.Generic.List<Kendo.Mvc.UI.TreeViewItemModel> NodeList =
        new System.Collections.Generic.List<Kendo.Mvc.UI.TreeViewItemModel>();

    foreach (CommonData.Domain.FollowType item in List)
    {
        NodeList.Add(new Kendo.Mvc.UI.TreeViewItemModel() { 
            Id = item.Id.ToString(), 
            Text = item.Title, 
            HasChildren = FollowTypeList.Exists(c => c.Id == item.ParentId) 
        });
    }

    return Json(NodeList, System.Web.Mvc.JsonRequestBehavior.AllowGet);
}

最佳答案

我猜在你的 javascript 代码中,id数据字段应为 Id (注意大小写):

return { id : data.Id };

关于asp.net-mvc - Kendo UI Treeview 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175927/

相关文章:

asp.net-mvc - datatables.net : Error handling for server side processing

asp.net-mvc - 如何在 ASP.NET MVC 中构造 moSTLy 静态页面

c# - 从 ItemsControl 绑定(bind)到父 DataTemplate 属性

c# - 带有命名空间的 XML 数据绑定(bind)

c# - Wpf 弹出窗口放置

c# - 生成和使用业务级事件的最佳实践建议

asp.net-mvc - MVC - 关注点分离

c# - 在我的 C# XAML Windows 8.1 应用程序中,如何进行编程绑定(bind)?

wpf - 如何将对象 bool 属性绑定(bind)到 CheckBox IsChecked 属性?

javascript - 失败 : Cannot read property 'bind' of undefined Protractor