Example of Diacritics Filtering in ASP.NET MVC MultiSelect Control
This sample demonstrates the diacritics filter functionality of the MultiSelect. Type the characters ‘gul’ in the MultiSelect element. It will display the suggestion list ignoring the diacritics lists.
@Html.UiMultiSelect("list", new UiMultiSelectOptions
{
Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList(),
Placeholder = "e.g: gul",
AllowFiltering = true,
IgnoreAccent = true
})
<style>
.control-wrapper { margin: 0 auto; width: 250px; }
</style>
<div class="control-section">
<div class="control-wrapper">
<div style="padding-top:70px;">
@Html.UiMultiSelect("list", new UiMultiSelectOptions
{
Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList(),
Placeholder = "e.g: gul",
AllowFiltering = true,
IgnoreAccent = true
})
</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/DiacriticsFiltering.cshtml; it draws what ViewData holds.
public ActionResult DiacriticsFiltering()
{
ViewData["data"] = new Diacritics().data;
return View();
}
public class Diacritics
{
public string[] data = new string[]{
"Águilas",
"Ajedrez",
"Ala Delta",
"Álbumes de Música",
"Alusivos",
"Análisis de Escritura a Mano",
"Dyarbakır",
"Derepazarı ",
"Gülümsemek ",
"Teşekkürler",
"Güle güle.",
"Gülhatmi",
"Gülünç"
};
}
}
}
@* 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 filtering will ignore the diacritics which makes it easier to filter the results in international characters lists when the ignoreAccent is enabled.
This sample illustrates using the international characters data.