How is the format for server-side validation of dates in ASP.NET MVC 4 configured? For instance, the following model field (‘BirthDate’) is only validated according to the format ‘MM/dd/yyyy’ on the client. On my server, apparently the format ‘dd/MM/yyyy’ is expected when POST-ed data is bound to the model.
[Required]
[Display(Name = "Date of Birth")]
[DisplayFormat(DataFormatString="{0:MM/dd/yyyy}", ApplyFormatInEditMode=true)]
[DataType(DataType.Date)]
public DateTime BirthDate { get; set; }
The validation of dates on ASP.NET MVC servers is linked to the configured culture. By default, the culture is unspecified and instead the Web client’s culture is adopted. So, for instance to make use of US date conventions on the server, edit the configuration/system.web/globalization element of your Web.config as follows (
uiCultureshouldn’t affect this validation, but I’ve added it for good measure):