Example of Default Functionalities in ASP.NET MVC ListBox Control
This sample demonstrates the default functionalities of a ListBox. Click any item to select a single item or ctrl + click to select multiple items.
Select your favorite car:
- 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
@Html.UiListBox("listbox", new UiListBoxOptions { DataSource = (IEnumerable<object>)ViewData["data"], Fields = new UiDropDownFields { Value = "id", Text = "text" } })
<style>
.control-section #listbox-control, .control-section #listbox-selection { margin: 0 auto; width: 300px; padding-top: 30px; }
.control-section h4 { margin: 0 0 8px; }
</style>
<div class="control-section">
<div id="listbox-control">
<h4>Select your favorite car:</h4>
@Html.UiListBox("listbox", new UiListBoxOptions { DataSource = (IEnumerable<object>)ViewData["data"], Fields = new UiDropDownFields { Value = "id", Text = "text" } })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ListBoxController : Controller
{
// The page is Views/ListBox/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
List<object> data = new List<object>();
data.Add(new { text = "Hennessey Venom", id = "list-01" });
data.Add(new { text = "Bugatti Chiron", id = "list-02" });
data.Add(new { text = "Bugatti Veyron Super Sport", id = "list-03" });
data.Add(new { text = "SSC Ultimate Aero", id = "list-04" });
data.Add(new { text = "Koenigsegg CCR", id = "list-05" });
data.Add(new { text = "McLaren F1", id = "list-06" });
data.Add(new { text = "Aston Martin One- 77", id = "list-07" });
data.Add(new { text = "Jaguar XJ220", id = "list-08" });
data.Add(new { text = "McLaren P1", id = "list-09" });
data.Add(new { text = "Ferrari LaFerrari", id = "list-10" });
ViewData["data"] = data;
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 ListBox is a graphical user interface component used to display a list of items. Users can select one or more items in the list using a checkbox or by keyboard selection. It supports sorting, grouping, reordering, and drag and drop of items.
In this sample, data is bound to the ListBox using the DataSource property. You can select your favorite cars from the ListBox.