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("object", new UiMultiSelectOptions
{
Placeholder = "Select a Item",
PopupHeight = "200px",
DataSource = Model.RecordList,
Fields = new UiDropDownFields { Text = "Text", Value = "ID" },
OnSelect = "valueChange",
OnChange = "valueChange"
})
<style>
.control-section .content { margin: 0 auto; width: 250px; }
.control-section h4 { margin: 0 0 8px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
@model DropdownsDemoController.MultiSelectRecord
<div class="control-section">
<div class="content" style="padding-top:15px">
@Html.UiMultiSelect("object", new UiMultiSelectOptions
{
Placeholder = "Select a Item",
PopupHeight = "200px",
DataSource = Model.RecordList,
Fields = new UiDropDownFields { Text = "Text", Value = "ID" },
OnSelect = "valueChange",
OnChange = "valueChange"
})
</div>
</div>
<div class="demo-property-panel" title="Properties">
<textarea id="value" style="width: 100%; height: 60px; background-color: inherit;" readonly>Selected value : </textarea>
</div>
<script>
// Syncfusion (AllowObjectBinding): the value is the records themselves, shown as JSON.
function valueChange() {
var chosen = window.Lumen.get('object').getValues();
var records = window.Lumen.get('object').getItems().filter(function (i) { return chosen.indexOf(i.value) >= 0; }).map(function (i) { return i.data; });
document.getElementById('value').value = 'Selected value : ' + JSON.stringify(records);
}
window.addEventListener('load', function () { setTimeout(valueChange, 0); });
</script>
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/ObjectValueBinding.cshtml; it draws what ViewData holds.
public ActionResult ObjectValueBinding()
{
MultiSelectRecord model = new MultiSelectRecord();
model.RecordList = new MultiSelectRecord().RecordModelList();
return View(model);
}
public class MultiSelectRecord
{
public string ID { get; set; }
public string Text { get; set; }
public string Group { get; set; }
public List<MultiSelectRecord> RecordList { set; get; }
public List<MultiSelectRecord> RecordModelList()
{
return Enumerable.Range(1, 150).Select(i => new MultiSelectRecord()
{
ID = i.ToString(),
Text = "Item " + i,
Group = "Group " + (char)('A' + (i - 1) % 4)
}).ToList();
}
}
}
}
@* 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.