jQuery Plugin for .NET Projects
Simply add class multiDD to your select element
<select class="multiDD" name="countries" multiple>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
</select>
Initialize with custom settings
$('#skills').multiSelectDD({
placeholder: 'Choose your skills',
max: 5,
closeOnSelect: false,
selectAll: false
});
Populate using JavaScript data array
$('#categories').multiSelectDD({
data: [
{ value: '1', text: 'Electronics', selected: true },
{ value: '2', text: 'Clothing' },
{ value: '3', text: 'Books' }
]
});
Load data dynamically from server
$('#products').multiSelectDD({
ajax: '/api/products',
pagination: {
enabled: true,
pageSize: 20
}
});
Controller:
public IActionResult Index()
{
ViewBag.Countries = new List<SelectListItem>
{
new SelectListItem { Value = "us", Text = "United States" },
new SelectListItem { Value = "uk", Text = "United Kingdom" }
};
return View();
}
Razor View:
<select name="countries" class="multiDD" multiple>
@foreach(var country in ViewBag.Countries)
{
<option value="@country.Value">@country.Text</option>
}
</select>
Get Values in Controller:
[HttpPost]
public IActionResult Save(List<string> countries)
{
// countries contains selected values
return RedirectToAction("Index");
}