|
| 1 | +--- |
| 2 | +title: DropDownTree |
| 3 | +page_title: DropDownTree | Telerik UI for ASP.NET Core HtmlHelpers |
| 4 | +description: "Learn the basics when working with the DropDownTree HtmlHelper for ASP.NET Core (MVC 6 or ASP.NET Core MVC)." |
| 5 | +slug: htmlhelpers_dropdowntree_aspnetcore |
| 6 | +position: 22 |
| 7 | +--- |
| 8 | + |
| 9 | +# DropDownTree HtmlHelper Overview |
| 10 | +As of the Kendo UI R2 2018, the DropDownTree is available in the Telerik UI for ASP.NET Core suite. |
| 11 | + |
| 12 | +The DropDownTree HtmlHelper extension is a server-side wrapper for the [Kendo UI DropDownTree](http://demos.telerik.com/kendo-ui/dropdowntree/index) widget. |
| 13 | + |
| 14 | +It allows you to configure the Kendo UI DropDownTree widget from server-side code. The [DropDownTree](http://docs.telerik.com/kendo-ui/controls/editors/dropdowntree/overview) widget represents an editor of hierarchical data, rendered in a tree-like structure, which provides multiple selection option and custom nodes. |
| 15 | + |
| 16 | +## Basic Usage |
| 17 | + |
| 18 | +The following example demonstrates how to define the DropDownTree by using the DropDownTree HtmlHelper. |
| 19 | + |
| 20 | +###### Example |
| 21 | + |
| 22 | +```tab-Razor |
| 23 | + @(Html.Kendo().DropDownTree() |
| 24 | + .Name("dropdowntree") |
| 25 | + .DataTextField("Name") |
| 26 | + .DataSource(dataSource => dataSource |
| 27 | + .Read(read => read |
| 28 | + .Action("Read_DropDownTreeData", "DropDownTree") |
| 29 | + ) |
| 30 | + ) |
| 31 | + ) |
| 32 | +``` |
| 33 | +```tab-Controller |
| 34 | + public class DropDownTreeController : Controller |
| 35 | + { |
| 36 | + public IActionResult Index() |
| 37 | + { |
| 38 | + return View(); |
| 39 | + } |
| 40 | +
|
| 41 | + public static IList<HierarchicalViewModel> GetHierarchicalData() |
| 42 | + { |
| 43 | + var result = new List<HierarchicalViewModel>() |
| 44 | + { |
| 45 | + new HierarchicalViewModel() { ID = 1, ParentID = null, HasChildren = true, Name = "Parent item" }, |
| 46 | + new HierarchicalViewModel() { ID = 2, ParentID = 1, HasChildren = true, Name = "Parent item" }, |
| 47 | + new HierarchicalViewModel() { ID = 3, ParentID = 1, HasChildren = false, Name = "Item" }, |
| 48 | + new HierarchicalViewModel() { ID = 4, ParentID = 2, HasChildren = false, Name = "Item" }, |
| 49 | + new HierarchicalViewModel() { ID = 5, ParentID = 2, HasChildren = false, Name = "Item" } |
| 50 | + }; |
| 51 | +
|
| 52 | + return result; |
| 53 | + } |
| 54 | +
|
| 55 | + public IActionResult Read_DropDownTreeData(int? id) |
| 56 | + { |
| 57 | + var result = GetHierarchicalData() |
| 58 | + .Where(x => id.HasValue ? x.ParentID == id : x.ParentID == null) |
| 59 | + .Select(item => new { |
| 60 | + id = item.ID, |
| 61 | + Name = item.Name, |
| 62 | + expanded = item.Expanded, |
| 63 | + imageUrl = item.ImageUrl, |
| 64 | + hasChildren = item.HasChildren |
| 65 | + }); |
| 66 | +
|
| 67 | + return Json(result); |
| 68 | + } |
| 69 | + } |
| 70 | +``` |
| 71 | + |
| 72 | +## Configuration |
| 73 | + |
| 74 | +The following example demonstrates the basic configuration of the DropDownTree HtmlHelper and how to get the DropDownTree instance. |
| 75 | + |
| 76 | +###### Example |
| 77 | + |
| 78 | +``` |
| 79 | + @(Html.Kendo().DropDownTree() |
| 80 | + .Name("dropdowntree") |
| 81 | + .Checkboxes(true) |
| 82 | + .DataTextField("Name") |
| 83 | + .DataSource(dataSource => dataSource |
| 84 | + .Read(read => read |
| 85 | + .Action("Employees", "DropDownTree") |
| 86 | + ) |
| 87 | + ) |
| 88 | +
|
| 89 | + ) |
| 90 | +
|
| 91 | + <script type="text/javascript"> |
| 92 | + $(function () { |
| 93 | + //Notice that the Name() of the DropDownTree is used to get its client-side instance. |
| 94 | + var dropdowntree = $("#dropdowntree").data("kendoDropDownTree"); |
| 95 | + console.log(dropdowntree); |
| 96 | + }); |
| 97 | + </script> |
| 98 | +``` |
| 99 | + |
| 100 | +## See Also |
| 101 | + |
| 102 | +* [JavaScript API Reference of the DropDownTree](http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdowntree) |
| 103 | +* [DropDownTree HtmlHelper for ASP.NET MVC](http://docs.telerik.com/aspnet-mvc/helpers/dropdowntree/overview) |
| 104 | +* [DropDownTree Official Demos](http://demos.telerik.com/aspnet-core/dropdowntree/index) |
| 105 | +* [Overview of Telerik UI for ASP.NET Core]({% slug overview_aspnetmvc6_aspnetmvc %}) |
| 106 | +* [Get Started with Telerik UI for ASP.NET Core in ASP.NET Core Projects]({% slug gettingstarted_aspnetmvc6_aspnetmvc %}) |
| 107 | +* [Get Started with Telerik UI for ASP.NET Core in ASP.NET Core Projects on Linux]({% slug gettingstartedlinux_aspnetmvc6_aspnetmvc %}) |
| 108 | +* [Known Issues with Telerik UI for ASP.NET Core]({% slug knownissues_aspnetmvc6_aspnetmvc %}) |
0 commit comments