Calendar
Calendar
Validation
This sample shows how to set item-validator attribute to a function to determine whether dates
are valid for selection.
Features
Use this Calendar control to select a date. Notice you won't be able to select weekends.
January 2025
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
29 | 30 | 31 | 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2025 | |||
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
Description
This sample shows how to set item-validator attribute to a function to determine whether dates
are valid for selection.
1 2 3 4 5 6 7 8 9 10 11 12 | using Microsoft.AspNetCore.Mvc; namespace MvcExplorer.Controllers { public partial class CalendarController : Controller { public ActionResult Validation() { return View(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | @ { var today = DateTime.Now.Date; var minDate = new DateTime(today.Year, 1, 1); var maxDate = new DateTime(today.Year, 12, 31); } @section Scripts{ <script> function itemValidator(date) { var weekday = date.getDay(); return weekday != 0 && weekday != 6; } </script> } < div > < P > @Html .Raw(CalendarRes.Validation_Text0)</ P > < c1-calendar value = "@today" min = "@minDate" max = "@maxDate" item-validator = "itemValidator" width = "300px" > </ c1-calendar > </ div > @section Description{ @Html .Raw(CalendarRes.Validation_Text1) } |