New to Telerik UI for ASP.NET MVCStart a free 30-day trial

TreeView Binding

The TreeView provides support for declaratively defining its items and for local (on the server) and remote (using a DataSource configuration object) binding.

Do not use the names of the kendo.data.Node fields and methods (for example, children) as fields in the TreeView data.

Declaring TreeView Items

The TreeView allows you to declare all its items within the helper declaration.

The following example demonstrates how to configure a TreeView with three levels of hierarchy.

Razor
    @(Html.Kendo().TreeView()
        .Name("treeview")
        .Items(treeview =>
        {
            treeview.Add().Text("My Web Site")
                .Items(root =>
                {
                    root.Add().Text("images")
                        .Items(images =>
                        {
                            images.Add().Text("logo.png");
                            images.Add().Text("body-back.png");
                        });
                    root.Add().Text("about.html");
                    root.Add().Text("contacts.html");
                });
        })
    )

Local Data Binding

You can bind the TreeView locally on the server by passing the appropriate collection to the HTML helper BindTo() method.

Razor
@(Html.Kendo().TreeView()
    .Name("treeview-left")
    .BindTo((IEnumerable<TreeViewItemModel>)ViewBag.treeData)
)

Remote Data Binding

The TreeView provides support for remote data binding by using a DataSource configuration object.

Razor
@(Html.Kendo().TreeView()
    .Name("treeview")
    .DataTextField("Name")
    .DataSource(dataSource => dataSource
        .Read(read => read
            .Action("Read_TreeViewData", "TreeView")
        )
    )
)

By default, the TreeView sends to the remote endpoint the id of the expanded node. To send additional data use the DataSource Data method and provide the name of a JavaScript function which will return a JavaScript object with the additional data.

See Also