Example of Default Functionalities in ASP.NET MVC MultiSelect Control
This sample demonstrates the default functionalities of the MultiSelect. Type a character in the MultiSelect element or click on this element to choose one or more items from the suggestion list.
@Html.UiMultiSelect("default", new UiMultiSelectOptions { Mode = UiMultiSelectMode.Default, Placeholder = "Favorite Sports", Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList() })
@Html.UiMultiSelect("box", new UiMultiSelectOptions { Mode = UiMultiSelectMode.Box, Placeholder = "Favorite Sports", Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList() })
@Html.UiMultiSelect("delimiter", new UiMultiSelectOptions { Mode = UiMultiSelectMode.Delimiter, Placeholder = "Favorite Sports", Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList() })
<style>
.control-section .content { margin: 0 auto; width: 250px; }
.control-section h4 { margin: 0 0 8px; }
</style>
<div class="control-section">
<div class="content" style="padding-top:15px">
<h4> Default Mode</h4>
@Html.UiMultiSelect("default", new UiMultiSelectOptions { Mode = UiMultiSelectMode.Default, Placeholder = "Favorite Sports", Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList() })
<h4 style="margin-top:24px">Box Mode</h4>
@Html.UiMultiSelect("box", new UiMultiSelectOptions { Mode = UiMultiSelectMode.Box, Placeholder = "Favorite Sports", Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList() })
<h4 style="margin-top:24px">Delimiter Mode</h4>
@Html.UiMultiSelect("delimiter", new UiMultiSelectOptions { Mode = UiMultiSelectMode.Delimiter, Placeholder = "Favorite Sports", Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList() })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MultiSelectController : Controller
{
// The page is Views/MultiSelect/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
ViewData["data"] = new string[] { "American Football", "Badminton", "Basketball", "Cricket", "Football", "Golf", "Hockey", "Rugby", "Snooker", "Tennis" };
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 MultiSelect component contains a list of predefined values from that the user can choose multiple values.
In this sample, the selected items are shown with three different UI modes in three different MultiSelect elements. That three UI modes are listed below,
- Default - on focus-in, the component will act in
box modeand on blur, the component will act indelimiter mode. - Box - selected items will be visualized in chip.
- Delimiter - selected items will be visualized in text content.