Example of Disabled Dates in ASP.NET MVC DateTimePicker 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 DateTimePicker.
@Html.UiDateTimePicker("datetime", new UiDateTimePickerOptions { Placeholder = "Select a date and time", OnRenderDayCell = "disableDate" })
<style>
#wrapper { max-width: 246px; margin: 30px auto; padding-top: 50px; }
</style>
<div class="control-section">
<div id="wrapper">
@Html.UiDateTimePicker("datetime", new UiDateTimePickerOptions { Placeholder = "Select a date and time", OnRenderDayCell = "disableDate" })
</div>
</div>
<script>
// Syncfusion: the weekends are disabled.
function disableDate(args) {
if (args.date.getDay() === 0 || args.date.getDay() === 6) {
args.isDisabled = true;
}
}
</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/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 specific dates in the Calendar by using renderDayCell event. This event gets triggered on each day cell element creation, that allows you to customize, or disable specific dates in the Calendar. Here the weekend dates are disabled by using renderDayCell.