Example of Template in ASP.NET MVC DropDownTree Control
This sample explains you about the template functionalities of the Dropdown Tree. Click the Dropdown Tree element, and then select an item from the customized list.

${name}
${job}
Employee List
${name} - ${job}
@Html.UiDropDownTree("ddt", new UiDropDownTreeOptions
{
Placeholder = "Select an employee",
Width = "370px",
PopupHeight = "250px",
DataSource = (IEnumerable<object>)ViewData["data"],
Fields = new UiDropDownFields { Value = "id", Text = "name", ParentValue = "pid", Expanded = "expanded" },
ItemTemplate = "#treeItem",
HeaderTemplate = "#treeHeader",
FooterTemplate = "#treeFooter",
ValueTemplate = "#treeValue"
})
<style>
.tnode { display: flex; align-items: center; gap: 8px; }
.tnode .eimage { width: 36px; height: 36px; border-radius: 50%; }
.tnode .ename { font-weight: 600; }
.tnode .ejob { font-size: 12px; opacity: .7; }
.tnode .status { margin-left: auto; }
.status { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.status.online { background: #4caf50; }
.status.busy { background: #e53935; }
.status.away { background: #fb8c00; }
.head { padding: 8px 12px; font-weight: 600; border-bottom: 1px solid #ddd; }
.footer { padding: 8px 12px; border-top: 1px solid #ddd; font-size: 12px; }
.footer .display { margin-right: 12px; }
</style>
<template id="treeItem"><div class="tnode"><img class="eimage" src="@Url.Content("~/Content/images/dropdown-tree/")${image}.png" alt="employee"/><div><div class="ename">${name}</div><div class="ejob">${job}</div></div><span class="status ${status}"></span></div></template>
<template id="treeHeader"><div class="head">Employee List</div></template>
<template id="treeFooter"><div class="footer"><span class="display"><span class="status online"></span>Available</span><span class="display"><span class="status busy"></span>Busy</span><span class="display"><span class="status away"></span>Away</span></div></template>
<template id="treeValue"><div>${name} - ${job}</div></template>
<div class="control-section">
<div style="margin: 0 auto; width:370px; padding-top:75px">
@Html.UiDropDownTree("ddt", new UiDropDownTreeOptions
{
Placeholder = "Select an employee",
Width = "370px",
PopupHeight = "250px",
DataSource = (IEnumerable<object>)ViewData["data"],
Fields = new UiDropDownFields { Value = "id", Text = "name", ParentValue = "pid", Expanded = "expanded" },
ItemTemplate = "#treeItem",
HeaderTemplate = "#treeHeader",
FooterTemplate = "#treeFooter",
ValueTemplate = "#treeValue"
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DropDownTreeController : Controller
{
// The page is Views/DropDownTree/Template.cshtml; it draws what ViewData holds.
public ActionResult Template()
{
ViewData["data"] = new DropDownTreeTemplate().Template();
return View();
}
public class DropDownTreeTemplate
{
public List<Object> Template()
{
List<object> localData = new List<object>();
localData.Add(new { id = 1, name = "Steven Buchanan", hasChild = true, expanded = true, image = "10", job = "General Manager", status = "busy" });
localData.Add(new { id = 2, pid = 1, name = "Laura Callahan", image = "2", job = "Product Manager", hasChild = true, status = "online" });
localData.Add(new { id = 3, pid = 2, name = "Andrew Fuller", image = "7", job = "Team Lead", hasChild = true, status = "away" });
localData.Add(new { id = 4, pid = 3, name = "Anne Dodsworth", image = "1", job = "Developer", status = "busy" });
localData.Add(new { id = 5, pid = 3, name = "Lilly", image = "5", job = "Developer", status = "online" });
localData.Add(new { id = 6, pid = 1, name = "Nancy Davolio", image = "4", job = "Product Manager", hasChild = true, status = "online" });
localData.Add(new { id = 7, pid = 6, name = "Michael Suyama", image = "9", job = "Team Lead", hasChild = true, status = "away" });
localData.Add(new { id = 8, pid = 7, name = "Robert King", image = "8", job = "Developer", status = "busy" });
localData.Add(new { id = 9, pid = 7, name = "Mary", image = "6", job = "Developer", status = "away" });
localData.Add(new { id = 10, pid = 1, name = "Janet Leverling", image = "3", job = "HR", status = "online" });
return localData;
}
}
}
}
@* 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 Dropdown Tree has been provided with several options to customize each list items, header, and footer elements.
This sample uses the following list of templates in the Dropdown Tree
ItemTemplate- To customize the list item's content.HeaderTemplate- To customize the header element.FooterTemplate- To customize the footer element.valueTemplate- To customize the selected item's element.