Example of Nested List in ASP.NET MVC ListView Control
This sample demonstrates the nested list functionalities, which allows you to navigate to the sub list items by clicking any item and navigating back to the list item using the back icon at the top left.
Folder
- Music
- Videos
- Documents
- Pictures
- Downloads
@Html.UiListView(new UiListViewOptions { Id = "nestedlist", ShowHeader = true, HeaderTitle = "Folder", ShowIcon = true, Items = (List<UiListItem>)ViewData["dataSource"] })
<style>
.control-section { max-width: 700px; margin: 0 auto; padding: 10px 20px; }
.control-section h4 { margin: 14px 0 6px; }
#flat-list, #group-list { display: inline-block; vertical-align: top; width: 48%; min-width: 260px; margin-right: 1%; }
.lv-row { display: grid; grid-template-columns: 44px 1fr; column-gap: 12px; align-items: center; width: 100%; box-sizing: border-box; padding: 6px 4px; }
.lv-contact { grid-template-columns: 44px 1fr; }
.lv-avatar { display: inline-flex; width: 36px; height: 36px; align-items: center; justify-content: center; border-radius: 50%; background: var(--ui-row-hover-bg); font-size: 14px; font-weight: 600; flex: none; }
</style>
<div class="control-section">
@Html.UiListView(new UiListViewOptions { Id = "nestedlist", ShowHeader = true, HeaderTitle = "Folder", ShowIcon = true, Items = (List<UiListItem>)ViewData["dataSource"] })
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ListViewController : Controller
{
// The page is Views/ListView/NestedList.cshtml; it draws what ViewData holds.
public ActionResult NestedList()
{
ViewData["dataSource"] = new List<UiListItem>
{
new UiListItem { Value = "01", Text = "Music", IconCss = "e-icons e-folder", Children = new List<UiListItem> { new UiListItem { Value = "01-01", Text = "Gouttes.mp3", IconCss = "e-icons e-file" } } },
new UiListItem { Value = "02", Text = "Videos", IconCss = "e-icons e-folder", Children = new List<UiListItem> { new UiListItem { Value = "02-01", Text = "Naturals.mp4", IconCss = "e-icons e-file" }, new UiListItem { Value = "02-02", Text = "Wild.mpeg", IconCss = "e-icons e-file" } } },
new UiListItem { Value = "03", Text = "Documents", IconCss = "e-icons e-folder", Children = new List<UiListItem> { new UiListItem { Value = "03-01", Text = "Environment Pollution.docx", IconCss = "e-icons e-file" }, new UiListItem { Value = "03-02", Text = "Global Water, Sanitation, & Hygiene.docx", IconCss = "e-icons e-file" }, new UiListItem { Value = "03-03", Text = "Global Warming.ppt", IconCss = "e-icons e-file" }, new UiListItem { Value = "03-04", Text = "Social Network.pdf", IconCss = "e-icons e-file" }, new UiListItem { Value = "03-05", Text = "Youth Empowerment.pdf", IconCss = "e-icons e-file" } } },
new UiListItem { Value = "04", Text = "Pictures", IconCss = "e-icons e-folder", Children = new List<UiListItem> { new UiListItem { Value = "04-01-02", Text = "WIN_20160726_094118.JPG", IconCss = "e-icons e-file" }, new UiListItem { Value = "04-01-03", Text = "WIN_20160726_094119.JPG", IconCss = "e-icons e-file" } } },
new UiListItem { Value = "05", Text = "Downloads", IconCss = "e-icons e-folder", Children = new List<UiListItem> { new UiListItem { Value = "05-01", Text = "UI-Guide.pdf", IconCss = "e-icons e-file" }, new UiListItem { Value = "05-04", Text = "TypeScript.7z", IconCss = "e-icons e-file" } } }
};
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 ListView component supports nested list. To achieve list navigation, the Child property should be defined for the nested list in the array of JSON.
This sample have nested folder with the sub folders or files.