Example of Default Functionalities in ASP.NET MVC TreeView Control
This ASP.NET MVC TreeView example demonstrates the default functionalities of the TreeView. Click on node to select it, and click on icon or double click on node to expand/collapse it. The child nodes will be loaded on expand the parent node.
- ASP.NET MVC Team
- Smith
- Johnson
- Anderson
- Windows Team
- Clark
- Wright
- Lopez
@Html.UiTreeView(new UiTreeViewOptions { Id = "tree", Nodes = (List<UiTreeNode>)ViewData["fields"] })
<style>
.control_wrapper { max-width: 500px; margin: auto; border: 1px solid #dddddd; border-radius: 3px; }
</style>
<div class="control-section">
<div class="control_wrapper">
@Html.UiTreeView(new UiTreeViewOptions { Id = "tree", Nodes = (List<UiTreeNode>)ViewData["fields"] })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TreeViewController : Controller
{
// The page is Views/TreeView/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
ViewData["fields"] = new List<UiTreeNode>
{
new UiTreeNode { Id = "t1", Text = "ASP.NET MVC Team", Expanded = true, Children =
{
new UiTreeNode { Id = "t2", Text = "Smith" },
new UiTreeNode { Id = "t3", Text = "Johnson", Selected = true },
new UiTreeNode { Id = "t4", Text = "Anderson" }
} },
new UiTreeNode { Id = "t5", Text = "Windows Team", Expanded = true, Children =
{
new UiTreeNode { Id = "t6", Text = "Clark" },
new UiTreeNode { Id = "t7", Text = "Wright" },
new UiTreeNode { Id = "t8", Text = "Lopez" }
} }
};
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The TreeView component is used to display the data in a hierarchical structure with the configuration options to control the way of data is presented and manipulated. It will pull the data from a data source, such as an array of JSON objects, OData web services, or DataManager binding data fields to the fields property.
In this demo, the TreeView is populated with its minimum default settings.