Example of Node Editing in ASP.NET MVC TreeView Control
This ASP.NET MVC TreeView example demonstrates the node editing functionalities of the TreeView. Double click on the node or press F2 key on selected node to edit node text in input textbox. Press enter key or click outside of the input element to save the node, or press escape key to cancel the modified text.
- ASP.NET MVC Team
- Smith
- Johnson
- Anderson
- Windows Team
- Clark
- Wright
- Lopez
@Html.UiTreeView(new UiTreeViewOptions { Id = "nodeediting", AllowEditing = true, Nodes = (List<UiTreeNode>)ViewData["nodefields"] })
<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 = "nodeediting", AllowEditing = true, Nodes = (List<UiTreeNode>)ViewData["nodefields"] })
</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/NodeEditing.cshtml; it draws what ViewData holds.
public ActionResult NodeEditing()
{
ViewData["nodefields"] = 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 has the built-in option to edit and modify the node text in inline by enabling the allowEditing property.