Example of Default Functionalities in ASP.NET MVC ListView Control
This sample demonstrates the default functionalities of the ListView. Click any item from the list to select and highlight it.
Flat List
- Hennessey Venom
- Bugatti Chiron
- Bugatti Veyron Super Sport
- SSC Ultimate Aero
- Koenigsegg CCR
- McLaren F1
- Aston Martin One- 77
- Jaguar XJ220
- McLaren P1
- Ferrari LaFerrari
- Mercedes-Benz Aston Martin
- Zenvo ST1
- Lamborghini Veneno
Group List
- Audi
- Audi A4
- Audi A4
- Audi A5
- Audi A6
- Audi A7
- Audi A8
- BMW
- BMW 501
- BMW 502
- BMW 503
- BMW 507
- BMW 3200
@Html.UiListView(new UiListViewOptions { Id = "listview", Items = (List<UiListItem>)ViewData["dataSource"] })
@Html.UiListView(new UiListViewOptions { Id = "listviewgrp", Items = (List<UiListItem>)ViewData["groupData"] })
<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">
<div id="flat-list">
<h4>Flat List</h4>
@Html.UiListView(new UiListViewOptions { Id = "listview", Items = (List<UiListItem>)ViewData["dataSource"] })
</div>
<div id="group-list">
<h4>Group List</h4>
@Html.UiListView(new UiListViewOptions { Id = "listviewgrp", Items = (List<UiListItem>)ViewData["groupData"] })
</div>
</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/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
ViewData["groupData"] = new List<UiListItem>
{
new UiListItem { Value = "9bdb", Text = "Audi A4", GroupBy = "Audi" },
new UiListItem { Value = "9bdb", Text = "Audi A4", GroupBy = "Audi" },
new UiListItem { Value = "4589", Text = "Audi A5", GroupBy = "Audi" },
new UiListItem { Value = "e807", Text = "Audi A6", GroupBy = "Audi" },
new UiListItem { Value = "a0cc", Text = "Audi A7", GroupBy = "Audi" },
new UiListItem { Value = "5e26", Text = "Audi A8", GroupBy = "Audi" },
new UiListItem { Value = "f849", Text = "BMW 501", GroupBy = "BMW" },
new UiListItem { Value = "7aff", Text = "BMW 502", GroupBy = "BMW" },
new UiListItem { Value = "b1da", Text = "BMW 503", GroupBy = "BMW" },
new UiListItem { Value = "de2f", Text = "BMW 507", GroupBy = "BMW" },
new UiListItem { Value = "b2b1", Text = "BMW 3200", GroupBy = "BMW" }
};
ViewData["dataSource"] = new List<UiListItem>
{
new UiListItem { Value = "list-01", Text = "Hennessey Venom" },
new UiListItem { Value = "list-02", Text = "Bugatti Chiron" },
new UiListItem { Value = "list-03", Text = "Bugatti Veyron Super Sport" },
new UiListItem { Value = "list-04", Text = "SSC Ultimate Aero" },
new UiListItem { Value = "list-05", Text = "Koenigsegg CCR" },
new UiListItem { Value = "list-06", Text = "McLaren F1" },
new UiListItem { Value = "list-07", Text = "Aston Martin One- 77" },
new UiListItem { Value = "list-08", Text = "Jaguar XJ220" },
new UiListItem { Value = "list-09", Text = "McLaren P1" },
new UiListItem { Value = "list-10", Text = "Ferrari LaFerrari" },
new UiListItem { Value = "list-11", Text = "Mercedes-Benz Aston Martin" },
new UiListItem { Value = "list-12", Text = "Zenvo ST1" },
new UiListItem { Value = "list-13", Text = "Lamborghini Veneno" }
};
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 represents data in interactive hierarchical structure interface across different layouts or views, that also has the features such as data binding, template rendering, and grouping.
The group list allows you to group the relevant items under a logical category by mapping the GroupBy field.
In this sample, Cars are grouped based on their Category.