April 9, 2010
Telerik Calendar Control Intro for ASP.NET MVC
Posted by Brian Mains under ASP.NET MVC, WebNo Comments
The latest release of the open source Telerik ASP.NET MVC framework contains a new calendar control. This control functions similar to the ASP.NET AJAX calendar extender calendar, where it shows a month view, year view, and decade view, and responds to clicks on the client. Telerik can also specially process clicks for the server too. Let’s take a look at the calendar. I’m assuming you are familiar with the telerik component setup.
<%
Html.Telerik().Calendar().Name(“Cal1”)
.MinDate(new DateTime(DateTime.Today.Year – 1, 1, 1))
.MaxDate(new DateTime(DateTime.Today.Year + 1, 12, 31))
.Selection((sel) =>
{
sel.Action(“SelectedDate”, new { selected = true });
}).Render();
%>
The calendar control can regulate the minimum and maximum dates that can be selected (here a three year range is valid). This restriction is valid for all three calendar views too. The other option processes a calendar click by redirecting to another action method (hence the Action method) called SelectedDate.
The calendar (using the Vista style) looks like the following in month view:
Clicking on the header goes into year view:
Clicking on the header again goes into decade view:
And drilling back down by selecting the year, month, and day causes a redirection to the URL http://localhost/Calendar/SelectedDate?selected=4/8/2010, which is an action method in the calendar controller that we specified above. Also, we specified a selected property with a boolean; that boolean gets overridden and it uses the selected property to store the selected date. You can call this whatever you want.