Example of Template in ASP.NET MVC MultiSelect Control
This sample demonstrates the template functionalities of the MultiSelect. Type a character in the MultiSelect element or click on this element to choose one or more items from the customized list.

${Name}
${Designation}
Photo Employee Info

${Name}
@Html.UiMultiSelect("employees", new UiMultiSelectOptions
{
DataSource = (IEnumerable<DropdownsDemoController.Employees>)ViewData["data"],
Placeholder = "Select an employees",
Mode = UiMultiSelectMode.Box,
PopupHeight = "270px",
Fields = new UiDropDownFields { Text = "Name" },
ItemTemplate = "#employeeItem",
HeaderTemplate = "#employeeHeader",
ValueTemplate = "#employeeValue"
})
<style>
.control-wrapper { margin: 0 auto; width: 300px; }
.header { font-weight: 600; color: rgba(0, 0, 0, .54); height: 48px; padding: 15px 0 0 16px; font-size: 16px; background-color: #f5f5f5; }
.info { margin-left: 17px; }
.ename { display: block !important; opacity: .87; font-size: 16px; margin-top: 8px; }
.name { padding: 5px 42px; opacity: .87; line-height: 1.063em; }
.job { opacity: .54; font-size: 14px; margin-top: -15px; margin-bottom: 7px; }
.empImage { margin: 6px 16px; width: 40px; height: 40px; float: left; }
.value { margin: 3px 0 0 3px; float: left; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<template id="employeeItem"><div><img class="empImage" src="@Url.Content("~/Content/dropdownlist/images/Employees/")${Eimg}.png" alt="employee" /><div class="ename"> ${Name} </div><div class="job"> ${Designation} </div></div></template>
<template id="employeeHeader"><div class="header"> <span>Photo</span> <span class="info">Employee Info</span></div></template>
<template id="employeeValue"><div style="width:100%;height:100%;"><img class="value" src="@Url.Content("~/Content/dropdownlist/images/Employees/")${Eimg}.png" height="26px" width="26px" alt="employee" /><div class="name"> ${Name} </div></div></template>
<div class="control-section" style="height: 400px;">
<div class="control-wrapper">
<div style="padding-top:75px;">
@Html.UiMultiSelect("employees", new UiMultiSelectOptions
{
DataSource = (IEnumerable<DropdownsDemoController.Employees>)ViewData["data"],
Placeholder = "Select an employees",
Mode = UiMultiSelectMode.Box,
PopupHeight = "270px",
Fields = new UiDropDownFields { Text = "Name" },
ItemTemplate = "#employeeItem",
HeaderTemplate = "#employeeHeader",
ValueTemplate = "#employeeValue"
})
</div>
</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/Template.cshtml; it draws what ViewData holds.
public ActionResult Template()
{
ViewData["data"] = new Employees().EmployeesList();
return View();
}
public class Employees
{
public string Name { get; set; }
public string Eimg { get; set; }
public string Designation { get; set; }
public string Country { get; set; }
public List<Employees> EmployeesList()
{
List<Employees> emp = new List<Employees>();
emp.Add(new Employees { Name= "Andrew Fuller", Eimg= "7", Designation = "Team Lead", Country= "England"});
emp.Add(new Employees { Name= "Anne Dodsworth", Eimg= "1", Designation = "Developer", Country= "USA"});
emp.Add(new Employees { Name= "Janet Leverling", Eimg= "3", Designation = "HR", Country= "USA"});
emp.Add(new Employees { Name= "Laura Callahan", Eimg= "2", Designation = "Product Manager", Country= "USA"});
emp.Add(new Employees { Name= "Margaret Peacock", Eimg= "6", Designation = "Developer", Country= "USA"});
emp.Add(new Employees { Name= "Michael Suyama", Eimg= "9", Designation = "Team Lead", Country= "USA"});
emp.Add(new Employees { Name= "Nancy Davolio", Eimg= "4", Designation = "Product Manager", Country= "USA"});
emp.Add(new Employees { Name= "Robert King", Eimg= "8", Designation = "Developer ", Country= "England"});
emp.Add(new Employees { Name= "Steven Buchanan", Eimg= "10", Designation = "CEO", Country= "England" });
return emp;
}
}
}
}
@* 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 has been provided with several options to customize each list items, group title, selected value, header and footer elements.
This sample uses the following list of templates in MultiSelect.
-
ItemTemplate- To customize the list item's content. -
ValueTemplate- To customize the value element content that holds the selected item's text. -
HeaderTemplate- To customize the header element.