DatePicker
Edit this docThe DatePicker HtmlHelper extension is a server-side wrapper for the Kendo UI DatePicker widget.
Getting Started
Here is how to configure a simple Kendo DatePicker:
Make sure you have followed all the steps from the Introduction help topic.
Create a new action method which renders the view:
public ActionResult Index()
{
return View();
}
Add a datepicker:
WebForms
<%: Html.Kendo().DatePicker()
.Name("datepicker") //The name of the datepicker is mandatory. It specifies the "id" attribute of the widget.
.Min(new DateTime(1900, 1, 1)) //Set min date of the datepicker
.Max(new DateTime(2099, 12, 31)) //Set min date of the datepicker
.Value(DateTime.Today) //Set the value of the datepicker
%>
Razor
@(Html.Kendo().DatePicker()
.Name("datepicker") //The name of the datepicker is mandatory. It specifies the "id" attribute of the widget.
.Min(new DateTime(1900, 1, 1)) //Set min date of the datepicker
.Max(new DateTime(2099, 12, 31)) //Set min date of the datepicker
.Value(DateTime.Today) //Set the value of the datepicker
)
You can reference an existing DatePicker instance via jQuery.data().
Once a reference has been established, you can use the API to control its behavior.
//Put this after your Kendo DatePicker for ASP.NET MVC declaration
<script>
$(function() {
// Notice that the Name() of the datepicker is used to get its client-side instance
var datepicker = $("#datepicker").data("kendoDatePicker");
});
</script>
You can subscribe to all events exposed by Kendo UI DatePicker:
<%: Html.Kendo().DatePicker()
.Name("datepicker")
.Events(e => e
.Open("datepicker_open")
.Close("datepicker_close")
.Change("datepicker_change")
)
%>
<script>
function datepicker_open() {
//Handle the open event
}
function datepicker_close() {
//Handle the close event
}
function datepicker_change() {
//Handle the change event
}
</script>
@(Html.Kendo().DatePicker()
.Name("datepicker")
.Events(e => e
.Open("datepicker_open")
.Close("datepicker_close")
.Change("datepicker_change")
)
)
<script>
function datepicker_open() {
//Handle the open event
}
function datepicker_close() {
//Handle the close event
}
function datepicker_change() {
//Handle the change event
}
</script>
@(Html.Kendo().DatePicker()
.Name("datepicker")
.Events(e => e
.Open(@<text>
function() {
//Handle the open event inline
}
</text>)
.Change(@<text>
function() {
//Handle the change event inline
}
</text>)
)
)
The DatePicker widget supports only DateTime structure. You will need to convert DateTimeOffset into DatePicker in order to show date and time correctly.
By default ASP.NET MVC project uses jQuery validate framework, which does not provide support for internationalized dates.
In other words, every string which Date.parse cannot define as valid date will be reported as invalid. As extending open source libraries is beyond of our product,
you will need to resolve this issue manually - check this link for more information.
You can also use Kendo Validator, which supports validating internationalized dates.