The field DateTime must be a date.
I am using Kendo grid in MVC project. I have both French and English version of the same application. The following is what I do in the _Layout.cshtml file:
<script>
if ("@Session["Culture"]" === "en-CA") {
kendo.culture("en-US");
Globalize.culture('en-CA');
} else {
kendo.culture("fr-CA");
Globalize.culture('fr-CA');
}
$.validator.methods.number = function (value, element) {
return this.optional(element) || !isNaN(Globalize.parseFloat(value));
}
$.validator.methods.date = function (value, element) {
if (this.optional(element))
return true;
var result = Globalize.parseDate(value, "@LCL.Common_Formats.DatePickerFormat", "@Session["Culture"]");
return !isNaN(result) && (result != null);
}
$.validator.methods.min = function (value, element, param) {
return this.optional(element) || Globalize.parseFloat(value) >= param;
}
$.validator.methods.max = function (value, element, param) {
return this.optional(element) || Globalize.parseFloat(value) <= param;
}
$.validator.methods.range = function (value, element, param) {
if (this.optional(element))
return true;
var result = Globalize.parseFloat(value);
return (result >= param[0] && result <= param[1]);
}
</script>
In the grid I have a datepicker as below:
c.Bound(u => u.DateTime)
.Title(LCL.Common_Labels.PurchaseDate)
.Format("{0:" + LCL.Common_Formats.DatePickerFormat + "}")
.Width(smlColumn);
LCL.Common_Formats.DatePickerFormat is an entry in the Resources file for storing the datepicker formats. I have both English and French Resource files. My problem is that I am getting this weird exception: The field DateTime must be a date when editing the record in the French version.
But it works very well in the English version...