Example of Globalization in ASP.NET MVC Calendar Control
In this sample, the calendar 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.
Selected Value:
Select a Locale
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", Culture = "de", OnChange = "startDate" })
@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>
#date_label { display: block; width: 248px; color: rgba(0, 0, 0, 0.58); margin-left: 5px; }
.control_wrapper { max-width: 300px; margin: 0 auto; }
.ui-theme-dark #date_label { color: white; }
.property-row { margin: 8px 0; }
</style>
<div class="control_wrapper">
<div id="calender-control">
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", Culture = "de", OnChange = "startDate" })
<br />
<span id="date_label"> Selected Value: </span>
</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>
var culture = 'de';
function show(value) {
if (value) { document.getElementById('date_label').textContent = 'Selected Value: ' + value.toLocaleDateString(culture); }
}
function startDate(value) { show(value); }
// Syncfusion: calendar.locale = the culture (Arabic also turns right to left); the label is written in it.
function onLocaleChange() {
var checked = document.querySelector('input[name="locale"]:checked');
if (!checked) { return; }
culture = checked.value;
var calendar = window.Lumen.get('calendar');
calendar.setCulture(culture);
show(calendar.getValue());
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class CalendarController : Controller
{
// The page is Views/Calendar/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 calendar component is rendered in German culture. Here, the date separator, week header, and month text content are updated based on current culture. You can also change the component culture by selecting it from the culture options in the properties panel.