Example of Diacritics Filtering in ASP.NET MVC ComboBox Control
This sample demonstrates the diacritics filter functionality of the ComboBox. Type the characters ‘gul’ in the ComboBox element and it displays the suggestion list ignoring the diacritics lists.
@Html.UiComboBox("list", new UiComboBoxOptions
{
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.UiComboBox("list", new UiComboBoxOptions
{
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 ComboBoxController : Controller
{
// The page is Views/ComboBox/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 ComboBox filtering will ignore the diacritics which makies it easier to filter the results in international characters lists when the ignoreAccent is enabled.
This sample illustrates the international characters data.