New to Telerik UI for ASP.NET MVC? Download free 30-day trial
ASP.NET MVC TreeView Local Data Binding
Loading Demo...
- EXAMPLE
- VIEW SOURCE
-
Change Theme
defaultDefault Theme
- Main
- Main Dark
- Nordic
- Ocean Blue
- Ocean Blue A11Y
- Purple
- Turquoise
Bootstrap Theme- Main
- Bootstrap 3
- Bootstrap 3 Dark
- Main Dark
- Nordic
- Turquoise
- Turquoise Dark
- Urban
- Vintage
Material Theme- Main
- Arctic
- Lime Dark
- Main Dark
- Material 2
- Material 2 Dark
- Nova
Classic Theme- Main
- Green
- Green Dark
- Lavender
- Lavender Dark
- Main Dark
- Metro
- Metro Dark
- Moonlight
- Opal
- Opal Dark
- Silver
- Silver Dark
- Uniform
Fluent Theme- Main
- Main Dark
local_data_binding.cshtml
Local_Data_BindingController.cs
Also available for:
CLIENT-SIDE API SERVER-SIDE APIDescription
Apart from declaratively defining the Telerik UI for ASP.NET MVC TreeView items within the helper configuration, you can bind the component 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:
- (Default) Using inline data—An
IEnumerableofTreeViewItemModelis stored in aViewBagand passed to theBindTo()method. TheTreeViewItemModel has anItemsfield that holds the child nodes (it is aListproperty). If a given node has items, the Expand icon will be visible. - Mapping Model properties—An
IEnumerableof a specified Model, for example,"CategoryItem", is stored in aViewBagand passed to another overload of theBindTo()method: the first argument is anIEnumerableof a Model, and the second is the action, which creates a hierarchy of items by using the specified mappings. For example, the child nodes will be bound to theSubCategoriesproperty, and theCategoryItemModel properties will be mapped toTreeViewItemproperties.
Additional Apps
This TreeView example is part of a 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, and edit them and their theme appearance in the ThemeBuilder.
Support & Learning Resources
Additional Resources