I have the following model and view, and I would very much like to accept date values in the format 'dd/MM/yyyy'. However, despite using the DisplayFormat
annotation, I still get a validation error using my chosen format.
[MetadataType(typeof(MilestoneMetadata))]
public partial class Milestone {
public class MilestoneMetadata {
[Required][DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public object Date { get; set; }
}
}
and the view:
<div class="editor-field">
<%: Html.EditorFor(model => model.Date) %>
<%: Html.ValidationMessageFor(model => model.Date) %>
</div>
Namespaces etc. are correct for the annotations and main classes to be in the same namespace. This is not my first encounter with this issue, but I see no results from annotations that are supposed to affect mappings between form values and the model. A template for dates doesn't help me because I can't find a way to set how dates are parsed when posting a create or update.
NOTE: I do not wish to use a different UI culture to achieve this.