Example of Disabled Items in ASP.NET MVC MultiSelect Control
This example showcases the disabled items of MultiSelect. When you click on the MultiSelect the popup will open, and you will notice that the disabled items are greyed out and cannot be selected.
@Html.UiMultiSelect("tag", new UiMultiSelectOptions
{
Placeholder = "Select Tags",
AllowFiltering = true,
DataSource = (IEnumerable<DropdownsDemoController.Tag>)ViewData["tagdata"],
Fields = new UiDropDownFields { Value = "ID", Text = "Text", Disabled = "State" }
})
@Html.UiMultiSelect("vegetable", new UiMultiSelectOptions
{
Placeholder = "Select Vegetables",
Mode = UiMultiSelectMode.CheckBox,
DataSource = (IEnumerable<DropdownsDemoController.VegetablesData>)ViewData["vegetabledata"],
Fields = new UiDropDownFields { GroupBy = "Category", Text = "Vegetable", Value = "ID", Disabled = "Status" }
})
<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">
<h3> Tags </h3>
@Html.UiMultiSelect("tag", new UiMultiSelectOptions
{
Placeholder = "Select Tags",
AllowFiltering = true,
DataSource = (IEnumerable<DropdownsDemoController.Tag>)ViewData["tagdata"],
Fields = new UiDropDownFields { Value = "ID", Text = "Text", Disabled = "State" }
})
<h3 style="margin-top:24px"> Vegetables </h3>
@Html.UiMultiSelect("vegetable", new UiMultiSelectOptions
{
Placeholder = "Select Vegetables",
Mode = UiMultiSelectMode.CheckBox,
DataSource = (IEnumerable<DropdownsDemoController.VegetablesData>)ViewData["vegetabledata"],
Fields = new UiDropDownFields { GroupBy = "Category", Text = "Vegetable", Value = "ID", Disabled = "Status" }
})
</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/DisabledItems.cshtml; it draws what ViewData holds.
public ActionResult DisabledItems()
{
ViewData["tagdata"] = new Tag().TagDataList();
ViewData["vegetabledata"] = new VegetablesData().VegetablesDataList();
return View();
}
public class VegetablesData
{
public string Vegetable { get; set; }
public string Category { get; set; }
public string ID { get; set; }
public bool Status { get; set; }
public List<VegetablesData> VegetablesDataList()
{
List<VegetablesData> veg = new List<VegetablesData>();
veg.Add(new VegetablesData { Vegetable = "Cabbage", Category = "Leafy and Salad", ID = "item1", Status = true });
veg.Add(new VegetablesData { Vegetable = "Pumpkins", Category = "Leafy and Salad", ID = "item2", Status = false });
veg.Add(new VegetablesData { Vegetable = "Spinach", Category = "Leafy and Salad", ID = "item3", Status = true });
veg.Add(new VegetablesData { Vegetable = "Wheat grass", Category = "Leafy and Salad", ID = "item4", Status = false });
veg.Add(new VegetablesData { Vegetable = "Yarrow", Category = "Leafy and Salad", ID = "item5", Status = false });
veg.Add(new VegetablesData { Vegetable = "Chickpea", Category = "Beans", ID = "item6", Status = true });
veg.Add(new VegetablesData { Vegetable = "Green bean", Category = "Beans", ID = "item7", Status = false });
veg.Add(new VegetablesData { Vegetable = "Horse gram", Category = "Beans", ID = "item8", Status = true });
veg.Add(new VegetablesData { Vegetable = "Garlic", Category = "Bulb and Stem", ID = "item9", Status = false });
veg.Add(new VegetablesData { Vegetable = "Nopal", Category = "Bulb and Stem", ID = "item10", Status = true });
veg.Add(new VegetablesData { Vegetable = "Onion", Category = "Bulb and Stem", ID = "item11", Status = false });
return veg;
}
}
public class Tag
{
public string ID { get; set; }
public string Text { get; set; }
public bool State { get; set; }
public List<Tag> TagDataList()
{
List<Tag> tag = new List<Tag>();
tag.Add(new Tag() { ID = "Item1", Text = "Add to KB", State = false });
tag.Add(new Tag() { ID = "Item2", Text = "Crisis", State = false });
tag.Add(new Tag() { ID = "Item3", Text = "Enhancement", State = true });
tag.Add(new Tag() { ID = "Item4", Text = "Presale", State = false });
tag.Add(new Tag() { ID = "Item5", Text = "Needs Approval", State = false });
tag.Add(new Tag() { ID = "Item6", Text = "Approved", State = true });
tag.Add(new Tag() { ID = "Item7", Text = "Internal Issue", State = true });
tag.Add(new Tag() { ID = "Item8", Text = "Breaking Issue", State = false });
tag.Add(new Tag() { ID = "Item9", Text = "New Feature", State = true });
tag.Add(new Tag() { ID = "Item10", Text = "New Component", State = false });
tag.Add(new Tag() { ID = "Item11", Text = "Mobile Issue", State = false });
return tag;
}
}
}
}
@* 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 provides options for individual items to be in either an enabled or disabled state for specific scenarios. Once an item is disabled, it cannot be selected as a value for the component. To configure the disabled item columns, use the fields.disabled property.