Example of Diacritics Filtering in ASP.NET MVC AutoComplete Control
This sample demonstrates the diacritics filter functionality of the AutoComplete. Type the characters ‘gul’ in the AutoComplete element and it displays the suggestion list ignoring the diacritics lists.
@Html.UiAutoComplete("list", new UiAutoCompleteOptions
{
Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList(),
Placeholder = "e.g: gul",
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.UiAutoComplete("list", new UiAutoCompleteOptions
{
Items = ((string[])ViewData["data"]).Select(text => new UiListItem(text, text)).ToList(),
Placeholder = "e.g: gul",
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 AutoCompleteController : Controller
{
// The page is Views/AutoComplete/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 AutoComplete 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.