Date Range in Calendar Control

19 Dec 20221 minute to read

Calendar provides an option to select a date value within a specified range by defining the min and max properties. The min date should always be lesser than the max date. If the value of min or max properties are changed through code behind, then update the value property to be set within the specified range. Or else, if the value is out of specified date range and less than min date, value property will be updated with min date or the value is higher than max date, value property will be updated with max date.

@Html.EJS().Calendar("element").Value(ViewBag.value).Min(ViewBag.minDate).Max(ViewBag.maxDate).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers
{
    public class CalendarController : Controller
    {
        public ActionResult DateRange()
        {
            ViewBag.minDate= new DateTime(DateTime.Now.Year,DateTime.Now.Month,07);
            ViewBag.maxDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 27);
            ViewBag.value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 14);
            return View();
        }
    }
}

NOTE

View Sample in GitHub.