I have a nullable DateTime property in my view model, and I'm binding it to a DatePicker, with a custom date format like so:
@Html.Kendo().DatePickerFor(model => model.MyNullableDateTimeField).HtmlAttributes(new { @class = "form-control" }).Format("MM/dd/yyyy").ParseFormats("MM/dd/yyyy", "yyyy-MM-dd").DateInput(true)
However, it displays like this:
And when I try to submit the form, I get a model validation error: "The value 'month/day/year' is not valid for <my property name>", and it is not possible for me to clear the text from the control at all.
If I input a valid date, it does submit correctly, but I need to be able to have a null value here. I tried
$("#MyNullableDateTimeField").data("kendoDatePicker").value(null) but that did not work. (also tried .val instead of .value)
Also, if there is anyway to have the DatePicker control submit the value in the more standard yyyy-MM-dd format, and just display it in the custom format, I would very much like to know that as well, as it would save me a lot of trouble. I don't understand why it submits a raw string in the "MM/dd/yyyy" format when a standard <input type="date"> will submit in a yyyy-MM-dd format and just display the value in the regular format.
Thanks!