Reputation: 754
I was create a page has Datepicker with dd/MM/yyyy format with culture ar-SA but when I try to set the date it's always returns invalid date here is the datepicker
@(Html.Kendo().DatePickerFor(model => model.ReviewDate)
.Name("ReviewDate")
.Format("dd/MM/yyyy")
)
The validation is always failed on form submit in some system. I have set culture to my JS document ready to kendo.culture("en-GB");
My Model is:
[DataType(DataType.Date)]
[DataMember(Name = "ReviewDate")]
[AllowHtml]
[DisplayName("Review Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime ReviewDate { get; set; }
Upvotes: 0
Views: 171
Reputation: 955
You need to set the culture and update the validator to satisfy the client-side validation
$(document).ready(function () {
kendo.culture("en-GB");
$.validator.addMethod('date',
function (value, element) {
return this.optional(element) || kendo.parseDate(value)
});
});
Also set your server culture too so it's the same by adding the following to your web.config under <system.web>
<globalization uiCulture="en-GB" culture="en-GB" enableClientBasedCulture="true" ></globalization>
I've used en-GB
but you can swap that out for other cultures e.g. ar-SA
if you want to use that instead
Upvotes: 1