Calendar
Calendar
Validation
This sample shows how to use ItemValidator function to determine whether the dates
are valid for a selection.
Features
Use this Calendar control to select a date. Notice that you won't be able to select weekends.
April 2025
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
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 | 1 | 2 | 3 |
2025 | |||
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
Description
This sample shows how to use ItemValidator function to determine whether the dates
are valid for a selection.
1 2 3 4 5 6 7 8 9 10 11 12 | using System.Web.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(Resources.Calendar.Validation_Text0)</ P > @ (Html.C1().Calendar().Value(today).Min(minDate).Max(maxDate).Width(300) .ItemValidator( "itemValidator" )) </ div > @section Description{ @Html .Raw(Resources.Calendar.Validation_Text1) } |