Example of Globalization in ASP.NET MVC DatePicker Control
In this sample, the DatePicker has been configured with German culture. To change this current culture, go to the properties panel at the right side and select a culture from the available options. For mobile mode touch the icon at the right side and select a culture from the available options.
Select a locale
@Html.UiDatePicker("datepicker", new UiDatePickerOptions { Culture = "de", Placeholder = "Wählen Sie ein Datum" })
@Html.UiRadioButton("locale", "en", false, new UiRadioButtonOptions { Id = "en", Label = "English", OnChange = "onLocaleChange" })
@Html.UiRadioButton("locale", "de", true, new UiRadioButtonOptions { Id = "de", Label = "German", OnChange = "onLocaleChange" })
@Html.UiRadioButton("locale", "ar", false, new UiRadioButtonOptions { Id = "ar", Label = "Arabic", OnChange = "onLocaleChange" })
<style>
#wrapper { max-width: 246px; margin: 30px auto; padding-top: 50px; }
#propertySection { margin: 0 auto; }
</style>
<div class="control-section">
<div id="wrapper">
<div id="datepicker-control">
@Html.UiDatePicker("datepicker", new UiDatePickerOptions { Culture = "de", Placeholder = "Wählen Sie ein Datum" })
</div>
</div>
</div>
<div class="demo-property-panel" title="Select a locale">
<h3>Select a locale</h3>
<div class="demo-property-row">@Html.UiRadioButton("locale", "en", false, new UiRadioButtonOptions { Id = "en", Label = "English", OnChange = "onLocaleChange" })</div>
<div class="demo-property-row">@Html.UiRadioButton("locale", "de", true, new UiRadioButtonOptions { Id = "de", Label = "German", OnChange = "onLocaleChange" })</div>
<div class="demo-property-row">@Html.UiRadioButton("locale", "ar", false, new UiRadioButtonOptions { Id = "ar", Label = "Arabic", OnChange = "onLocaleChange" })</div>
</div>
<script>
// Syncfusion: locale = the culture (Arabic also turns right to left); the placeholder is the culture's text.
var placeholders = { en: 'Choose a date', de: 'Wählen Sie ein Datum', ar: 'اختر تاريخا' };
function onLocaleChange() {
var checked = document.querySelector('input[name="locale"]:checked');
if (!checked) { return; }
var picker = window.Lumen.get('datepicker');
picker.setCulture(checked.value);
picker.input.placeholder = placeholders[checked.value];
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DatePickerController : Controller
{
// The page is Views/DatePicker/Globalization.cshtml; it draws what ViewData holds.
public ActionResult Globalization()
{
return View();
}
}
}
@* 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 DatePicker component is rendered with German culture. Here, the date separator, week header, and month text content are updated based on the current culture. You can also change the component culture by selecting it from the culture options in the properties panel.