Example of CheckBox in ASP.NET MVC MultiSelect Control
This sample demonstrates the checkbox functionalities of the MultiSelect. Click the MultiSelect element and then type a character in the search box. It will display the filtered list items based on the typed characters and then select the multiple values through the checkbox.
@Html.UiMultiSelect("checkList", new UiMultiSelectOptions
{
DataSource = (IEnumerable<DropdownsDemoController.CountriesData>)ViewData["data"],
Placeholder = "Select countries",
Mode = UiMultiSelectMode.CheckBox,
ShowDropDownIcon = true,
ShowSelectAll = true,
AllowFiltering = true,
FilterBarPlaceholder = "Search countries",
PopupHeight = "350px",
Fields = new UiDropDownFields { Text = "Name", Value = "Code" }
})
@Html.UiCheckBox("selectall", true, new UiCheckBoxOptions { Label = "Show Select All", OnChange = "selectallchange" })
@Html.UiCheckBox("dropicon", true, new UiCheckBoxOptions { Label = "DropDown Button", OnChange = "dropiconchange" })
@Html.UiCheckBox("reorder", true, new UiCheckBoxOptions { Label = "Selection Reorder", OnChange = "reorderchange" })
<style>
.control-section .content { margin: 0 auto; width: 250px; }
.control-section h4 { margin: 0 0 8px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="content" style="padding-top:15px">
<h4>CheckBox</h4>
@Html.UiMultiSelect("checkList", new UiMultiSelectOptions
{
DataSource = (IEnumerable<DropdownsDemoController.CountriesData>)ViewData["data"],
Placeholder = "Select countries",
Mode = UiMultiSelectMode.CheckBox,
ShowDropDownIcon = true,
ShowSelectAll = true,
AllowFiltering = true,
FilterBarPlaceholder = "Search countries",
PopupHeight = "350px",
Fields = new UiDropDownFields { Text = "Name", Value = "Code" }
})
</div>
</div>
<div class="demo-property-panel" title="Properties">
<div class="demo-property-row">@Html.UiCheckBox("selectall", true, new UiCheckBoxOptions { Label = "Show Select All", OnChange = "selectallchange" })</div>
<div class="demo-property-row">@Html.UiCheckBox("dropicon", true, new UiCheckBoxOptions { Label = "DropDown Button", OnChange = "dropiconchange" })</div>
<div class="demo-property-row">@Html.UiCheckBox("reorder", true, new UiCheckBoxOptions { Label = "Selection Reorder", OnChange = "reorderchange" })</div>
</div>
<script>
// Syncfusion: the check boxes set showSelectAll, showDropDownIcon and enableSelectionOrder of the MultiSelect.
function selectallchange(checkedValue) { window.Lumen.get('checkList').setShowSelectAll(checkedValue); }
function dropiconchange(checkedValue) { window.Lumen.get('checkList').setShowDropDownIcon(checkedValue); }
function reorderchange(checkedValue) { window.Lumen.get('checkList').setEnableSelectionOrder(checkedValue); }
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MultiSelectController : Controller
{
// The page is Views/MultiSelect/CheckBox.cshtml; it draws what ViewData holds.
public ActionResult CheckBox()
{
ViewData["data"] = new CountriesData().CountriesList();
return View();
}
public class CountriesData
{
public string Name { get; set; }
public string Code { get; set; }
public List<CountriesData> CountriesList()
{
List<CountriesData> country = new List<CountriesData>();
country.Add(new CountriesData { Name = "Australia", Code = "AU" });
country.Add(new CountriesData { Name = "Bermuda", Code = "BM" });
country.Add(new CountriesData { Name = "Canada", Code = "CA" });
// ... 16 more rows
return country;
}
}
private ActionResult Show(string method)
{
DropdownSample sample = (DropdownSample)ViewBag.DropdownSample;
// A sample keeps its data in a Prepare<Page> method (DropdownsDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod(method + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* 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>
@* Dropdowns with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The MultiSelect has built-in support to select the multiple values through checkbox, when the mode property is set as checkbox.
In this sample, the local data is bound to a collection of countries data. Also, provided options for the following:
To enable/disable the Select All feature in the property panel.
To enable/disable the DropDown Buttonfeature in the property panel.
To enable/disable the Selection Reorderfeature in the property panel.
The checkbox sample illustrates using the countries data.