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

Save the State of TreeView Items

Environment

ProductTelerik UI for ASP.NET MVC TreeView
Product VersionCreated with version 2024.4.1112

Description

How can I save the expanded and checked state of the TreeView items on the server and preserve it the next time the data is loaded?

Solution

  1. Define a TreeView that binds to remote data and handle its Change event.
Razor
@(Html.Kendo().TreeView()
    .Name("treeview")
    .Checkboxes(true)
    .DataTextField("Name")
    .DataSource(dataSource => dataSource
        .Read(read => read
            .Action("Read", "Home")
        )
        .Model(model =>
        {
            model.Id("ID");
            model.HasChildren("HasChildren");
        })
        .Events(events => events.Change("OnChange"))
    )
)

For a runnable example, refer to the ASP.NET MVC application in the UI for ASP.NET MVC Examples repository.

More ASP.NET MVC TreeView Resources

See Also