New to Telerik UI for ASP.NET Core? Download free 30-day trial
ASP.NET Core 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
- 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
HtmlHelper
TagHelper
local_data_binding.cshtml
Local_Data_BindingController.cs
CategoryItem.cs
SubCategoryItem.cs
Local_Data_Binding_TagHelper.cshtml
Also available for:
CLIENT-SIDE API HTML HELPER APIDescription
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:
- (Default) Using inline data—An
IEnumerable
ofTreeViewItemModel
is stored in aViewBag
and passed to theBindTo()
method. TheTreeViewItem
Model has anItems
field that holds the child nodes (it is aList
property). If a given node has items, the expand icon will be visible. - Mapping Model properties—An
IEnumerable
of a specified Model, for example,"CategoryItem"
, is stored in aViewBag
and passed to another overload of theBindTo()
method: the first argument is anIEnumerable
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 theSubCategories
property, and theCategoryItem
Model properties will be mapped toTreeViewItem
properties.
Additional Apps
This TreeView example is part of unique collection of hundreds of ASP.NET Core demos, with which you can see all Telerik ASP.NET Core 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 Telerik REPL for ASP.NET Core or ThemeBuilder.