Example of Globalization in ASP.NET MVC DateRangePicker Control
In this sample, the DateRangePicker 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.UiDateRangePicker("Rangepicker_start", "Rangepicker_end", new UiDateRangePickerOptions { Id = "Rangepicker", Culture = "de", Placeholder = "Einen Bereich auswählen" })
@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="Rangepicker-control">
@Html.UiDateRangePicker("Rangepicker_start", "Rangepicker_end", new UiDateRangePickerOptions { Id = "Rangepicker", Culture = "de", Placeholder = "Einen Bereich auswählen" })
</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: 'Select a range', de: 'Einen Bereich auswählen', ar: 'حدد نطاقا' };
function onLocaleChange() {
var checked = document.querySelector('input[name="locale"]:checked');
if (!checked) { return; }
var picker = window.Lumen.get('Rangepicker');
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 DateRangePickerController : Controller
{
// The page is Views/DateRangePicker/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>
DateRangePicker component was 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.