Example of Globalization in ASP.NET MVC DateTimePicker Control
In this sample, the DateTimePicker 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.UiDateTimePicker("datetimepicker", new UiDateTimePickerOptions { Culture = "de", Placeholder = "Wählen Sie ein Datum und eine Uhrzeit" })
@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="datetimepicker-control">
@Html.UiDateTimePicker("datetimepicker", new UiDateTimePickerOptions { Culture = "de", Placeholder = "Wählen Sie ein Datum und eine Uhrzeit" })
</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 datetime', de: 'Wählen Sie ein Datum und eine Uhrzeit', ar: 'اختر التاريخ والوقت' };
function onLocaleChange() {
var checked = document.querySelector('input[name="locale"]:checked');
if (!checked) { return; }
var picker = window.Lumen.get('datetimepicker');
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 DateTimePickerController : Controller
{
// The page is Views/DateTimePicker/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 DateTimePicker 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.