Example of Diacritics Filtering in ASP.NET MVC DropDownList Control
This sample demonstrates the diacritics filter functionality of the DropDownList. Type the characters ‘gul’ in the DropDownList filterbar, it will display the suggestion list ignoring the diacritics lists.
@Html.UiDropDownList("list", new UiDropDownListOptions
{
Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList(),
Placeholder = "Select a value",
FilterBarPlaceholder = "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.UiDropDownList("list", new UiDropDownListOptions
{
Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList(),
Placeholder = "Select a value",
FilterBarPlaceholder = "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 DropDownListController : Controller
{
// The page is Views/DropDownList/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 DropDownList 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 .