New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Telerik UI for ASP.NET MVC TreeView Local Data Binding

Loading Demo...
  • EXAMPLE
  • VIEW SOURCE
local_data_binding.cshtml
Local_Data_BindingController.cs

Also available for:

CLIENT-SIDE API SERVER-SIDE API

Description

Apart from declaratively defining the TreeView items within the helper configuration, the component can be bound to local or remote data based on your application requirements.

Binding the TreeView locally on the server can be implemented by passing the data collection to the BindTo() method.

The current demo illustrates two approaches for binding the TreeView to local data:

  • Inline data (default settings) - An IEnumerable of TreeViewItemModel is stored in a ViewBag and passed to the BindTo() method. The TreeViewItem Model has an Items field that holds the child nodes (it is a List property). If a given node has items, the expand icon will be visible.
  • Inline data - An IEnumerable of a specified Model (for example, "CategoryItem") is stored in a ViewBag and passed to another overload of the BindTo() method - the first argument is an IEnumerable of a Model, and the second is the action, which creates a hierarchy of items using the specified mappings. For example, the child nodes will be bound to the SubCategories property, and the CategoryItem Model properties will be mapped to TreeViewItem properties.
This TreeView example is part of unique collection of hundreds of ASP.NET MVC demos, with which you can see all Telerik ASP.NET MVC components and their features in action. View the source code of the demos from the library or directly adapt andedit their theme appearance in their theme appearance in the ThemeBuilder.

Support & Learning Resources

Additional Resources