This is a migrated thread and some comments may be shown as answers.

Treeview Local data binding 3 level in Razor.

0 Answers 114 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Wudhinun
Top achievements
Rank 1
Wudhinun asked on 24 Apr 2013, 01:10 PM
Hi,

I need to binding local data to treeview with data 3 level in razor. Can kendo UI work  ? 

Sample
   
     public class Level1
    {
        public string RootName {get;set;}
        public List<Level2> rootLevel2 {get;set;}
    }

    public class Level2
    {
        public string RootName { get; set; }
        public List<Level3> rootLevel3 {get;set;}
    }

    public class Level3{
          public string RootName { get; set; }
    }

CSHTML Page view

    @(Html.Kendo().TreeView()
            .Name("rootView")
            .BindTo((IEnumerable<Level1>)Model.Level1, (NavigationBindingFactory<TreeViewItem> mappings) =>
            {
                mappings.For<Level1>(binding => binding.ItemDataBound((item, root) =>
                {
                    item.Text = root.RootName;
                    item.Expanded = true;           
                })
                .Children(category => category.rootLevel2)
                );

                mappings.For<Level2>(binding => binding.ItemDataBound((item, root2) =>
                {
                    item.Text = root2.RootName;
                })
                .Children(category => category.rootLevel3)
                );

                mappings.For<Level3>(binding => binding.ItemDataBound((item, root3) =>
                {
                    item.Text = root3.ItemName;
                }));
            }))


There sample code above does not work for me, Always show error  "Sequence contains no elements"

Thank you in advance.

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Wudhinun
Top achievements
Rank 1
Share this question
or