Date Range
19 Dec 20221 minute to read
DatePicker provides an option to select a date value within a specified range by using the min and max properties. Always the min value has to be lesser than the max value.
When the min and max properties are configured and the selected date value is out-of-range or invalid, then the model value will be set to out of range
date value or null
respectively with highlighted error
class to indicate the date is out of range or invalid.
The value property depends on the min/max with respect to strictMode property.
The below example allows selecting a date within the range from 7th to 27th day in a month.
<ejs-datepicker id="datepicker" value="@ViewBag.value" min="@ViewBag.minDate" max="@ViewBag.maxDate" ></ejs-datepicker>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers
{
public partial class HomeController : Controller
{
public ActionResult DateRange()
{
ViewBag.value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,14);
ViewBag.minDate= new DateTime(DateTime.Now.Year,DateTime.Now.Month,07);
ViewBag.maxDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 27);
return View();
}
}
}
NOTE
If the value of
min
ormax
properties changed through code behind, then you have to update thevalue
property to set within the range.