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

ASP.NET Core DropDownTree Local Data Binding

Loading Demo...
  • EXAMPLE
  • VIEW SOURCE
HtmlHelper
TagHelper
Files:
local_data_binding.cshtml
Local_Data_Binding.cs
Local_Data_Binding_TagHelperController.cs
CategoryItem.cs
SubCategoryItem.cs
Local_Data_Binding_TagHelper.cshtml

Also available for:

CLIENT-SIDE API HTML HELPER API

Description

Apart from declaratively defining the DropDownTree items within the helper configuration, the component supports local (on the server) and remote (using a DataSource configuration object) data binding. Binding the DropDownTree locally on the server can be implemented by passing the data collection to the BindTo() method.

The current example demonstrates two approaches for binding the DropDownTree to local data:

  • (Default) Using inline data—An IEnumerable of DropDownTreeItemModel is stored in a ViewBag and passed to the BindTo() method. The DropDownTreeItemModel 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.
  • Mapping Model properties—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 by 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 DropDownTreeItem properties.

Additional Apps

This DropDownTree 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.

Support & Learning Resources

Additional Resources