So I have this property in my model:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MM-yyyy hh:mm}")]
[DataType(DataType.DateTime)]
public DateTime EventDate { set; get; }
I'm using a vuejs component for the datetime picker, so when the form is submitted the EventDate value looks like: "21-11-2017 20:47".
However on server side, in the controller action my model is always invalid: The value '21-11-2017 20:47' is not valid for EventDate.
Any idea what is wrong here? I've been trying different variations like using DateType.Date or other format strings, but the result was the same
[Update] The answers here suggest this is a duplicate of this question here
Although the other question is not the same, the last part of the answer there suggests what could be wrong in my case. It basically says that DisplaFormat with DataFormatString is ignored by model binder and I should either:
- create a custom model binder to make mvc understand my custom format for EventDate
- or use a standard date format that mvc understands by default
I guess there is no attribute yet to instruct mvc how to parse a date string during model binding, which is what I was hoping for..