Example of Islamic Calendar in ASP.NET MVC Calendar Control
The following example demonstrates the Hijri (Islamic) calendar. The Today date is always highlighted in the calendar and is focused on when no date is selected.
Selected Value:
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", CalendarMode = UiCalendarMode.Islamic, OnRenderDayCell = "customDates", OnChange = "valueChange" })
<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; }
.flatpickr-day.special { position: relative; }
.flatpickr-day.special span.highlight { position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: rgb(0, 0, 255); }
.flatpickr-day.special.birthday span.highlight { background: #ff6161; }
.flatpickr-day.special.dinner span.highlight { background: #e44; }
</style>
<div class="control_wrapper">
<div id="container" style="overflow:auto">
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", CalendarMode = UiCalendarMode.Islamic, OnRenderDayCell = "customDates", OnChange = "valueChange" })
<br />
<span id="date_label"> Selected Value: </span>
</div>
</div>
<script>
// Syncfusion: the 12th, 17th and 22nd of the Hijri month are disabled; the 13th (Dinner) and the 23rd (Holiday) are marked.
function customDates(args) {
if (args.date.getDate() === 12 || args.date.getDate() === 17 || args.date.getDate() === 22) {
args.isDisabled = true;
}
if (args.date.getDate() === 13) { mark(args, 'dinner', ' Dinner !'); }
if (args.date.getDate() === 23) { mark(args, 'holiday', ' Holiday !'); }
}
function mark(args, name, text) {
var dot = document.createElement('span');
dot.className = 'highlight';
args.element.classList.add('special', name);
args.element.setAttribute('data-val', text);
args.element.appendChild(dot);
}
function valueChange(value) {
document.getElementById('date_label').textContent = 'Selected Value: ' + new Intl.DateTimeFormat('en-u-ca-islamic-umalqura', { day: '2-digit', month: 'short', year: 'numeric' }).format(value);
}
</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/IslamicCalendar.cshtml; it draws what ViewData holds.
public ActionResult IslamicCalendar()
{
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 Hijri (Islamic) calendar is based on the lunar calendar. It consists of functionalities equivalent to those of the Gregorian Calendar like min, max date restriction, disabled dates, highlight dates, and multiple date selection.