Reputation: 19367
We are in the UK but have a US client. We want the date of a Kendo DatePicker to display in US format MM-dd-yyy
but, testing here, it won't accept any selection of a date value, stating that it must be a valid date.
I have applied .Format("MM-dd-yyyy")
to display the value, which works. I have attempted a couple of things to get it to accept a date selection, as you can see here:
@(Html
.Kendo()
.DatePickerFor(model => model.Date)
.Name("Date")
//.Format("MM-dd-yyyy")
//.ParseFormats(new[] { "dd/MM/yyyy", "dd-MM-yyyy", "MM-dd-yyyy" })
.Culture("en-US")
.HtmlAttributes(new { style = "width:150px" })
)
How can I get this to work?
Upvotes: 0
Views: 511
Reputation: 19367
Finally got this to work.
In JavaScript we can specify
kendo.culture("en-US");
but the key piece of code I used to get it to work was:
function OnSave(e) {
e.model.Date = (e.model.Date).toUTCString();
}
Even though e.model.Date
was already a valid (UK) date, toUTCString
enables an automatic conversion that Kendo/C# can convert to an acceptable date in the model.
Upvotes: 1