Calendar
Calendar
Overview
Features
Sample
Valid Range: Jan 1, 2020 to Dec 31, 2021
RepeatButtons = True: the calendar buttons (Previous and Next buttons) should act as repeat buttons, firing repeatedly as the button remains pressed.
ShowYearPicker = True: the calendar should display a list of years when the user clicks the header element on the year calendar.
Settings
Description
This sample shows the basic usage of the Calendar control.
Source
IndexController.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class CalendarController : Controller { public ActionResult Index() { ViewBag.DemoSettings = true; ViewBag.DemoSettingsModel = new ClientSettingsModel { Settings = CreateSettings() }; return View(); } private static IDictionary<string, object[]> CreateSettings() { var settings = new Dictionary<string, object[]> { {"FirstDayOfWeek", Enum.GetValues(typeof(DayOfWeek)).Cast<object>().ToArray()}, {"ShowHeader", new object[]{true, false}}, {"MonthView", new object[]{true, false}}, {"RepeatButtons", new object[]{true, false}}, {"ShowYearPicker", new object[]{true, false}} }; return settings; } } }
Index.cshtml
@{ var today = DateTime.Now.Date; var minDate = new DateTime(today.Year-1, 1, 1); var maxDate = new DateTime(today.Year, 12, 31); var format = Resources.Calendar.Index_DateFormat; ClientSettingsModel settings = ViewBag.DemoSettingsModel; } <div> <label>@Html.Raw(Resources.Calendar.Index_Text1)</label> @(Html.C1().Calendar().Id(settings.ControlId) .Value(today).Min(minDate).Max(maxDate).MonthView(true) .Width(300).RepeatButtons(true).ShowYearPicker(true) ) </div> <p> <b>@Html.Raw(Resources.Calendar.Index_ValidRange) <span>@minDate.ToString(format)</span> @Html.Raw(Resources.Calendar.Index_To) <span>@maxDate.ToString(format)</span></b> </p> <p> @Html.Raw(Resources.Calendar.Index_RepeatButtons)<br /> @Html.Raw(Resources.Calendar.Index_ShowYearPicker) </p> @section Description{ @Html.Raw(Resources.Calendar.Index_Text0) }
Documentation