I'm wokring an a multi-culture site which needs to validate form input, specifically the date entered by a user on the front end.
The problem i'm having is that vallues for annotations need to be constants,. I currently have:
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public string PreferredDate { get; set; }
However I would like the date format to be determined at runtime based on the culture, for example en-US would be MM/dd/yyyy whilst en-GB would be dd/MM/yyyy as above.
The problem as stated is that attribute arguments must be constants, so I can't do somethign like:
[DisplayFormat(DataFormatString = "{0:" + CultureInfo.CurrentCulture.DateTimeFormat.ToString() + "}", ApplyFormatInEditMode = true)]
Is there anyway around this?