Example of Disabled Dates in ASP.NET MVC Calendar Control
In the following sample, all the weekends (Saturday and Sunday) of a month are disabled, and these dates are restricted to set or select in the Calendar.
Selected Value:
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", OnRenderDayCell = "disableDate", 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; }
</style>
<div class="control_wrapper">
<div id="container" style="overflow:auto">
@Html.UiCalendar(new UiCalendarOptions { Id = "calendar", OnRenderDayCell = "disableDate", OnChange = "valueChange" })
<br />
<span id="date_label"> Selected Value: </span>
</div>
</div>
<script>
// Syncfusion: the weekends are disabled.
function disableDate(args) {
if (args.date.getDay() === 0 || args.date.getDay() === 6) {
args.isDisabled = true;
}
}
function valueChange(value) {
document.getElementById('date_label').textContent = 'Selected Value: ' + value.toLocaleDateString();
}
</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/DisabledDates.cshtml; it draws what ViewData holds.
public ActionResult DisabledDates()
{
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>
Disabled Dates sample demonstrates, how to disable a specific dates in the Calendar by using the renderDayCell event. This event gets triggered on each day cell element creation that allows you to customize or disable the specific dates in the Calendar. Here, the weekend date's are disabled by using renderDayCell.