I\'m using Kendo DatePicker to edit a Date field being displayed in a Kendo Grid in my ASP.NET MVC 4 project. In order to have the DatePicker being used for the Date field use c
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
[Required(ErrorMessage = "Pick a date from Kendo Date Picker")]
public DateTime mydate{ get; set; }
@(Html.Kendo().DatePickerFor(m=>m.mydate)
.Name("MyDate")
.Format("dd/MM/yyyy")
.ParseFormats(new string[] {"dd/MM/yyyy"}))
/Add script document.ready function/
$(document).ready(function () { kendo.culture("en-GB");
$.validator.methods['date'] = function (value, element) {
var check = false;
var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
if (re.test(value)) {
var adata = value.split('/');
var dd = parseInt(adata[0], 10);
var mm = parseInt(adata[1], 10);
var yyyy = parseInt(adata[2], 10);
var xdata = new Date(yyyy, (mm - 1), dd);
if ((xdata.getFullYear() == yyyy) && (xdata.getMonth() == (mm - 1)) &&
(xdata.getDate() == dd)) {
check = true;
}
else {
alert(value);
check = false;
}
} else
check = false;
return this.optional(element) || check;
}
});