The problem: I want to show a date in german-format with globalize. With the solution mentioned in MVc 5 - validation german date with unobtrusiv js - a simple approach it works in IE and Firefox - no Problem.
But Google-Chrome uses the input-type "date" and shows an datepicker. The Validation ever failed.
After reading a lot of answers here at stackoverflow I came to this solution:
In the model I introduce a new, not mapped property:
This is necessary to add the dataannotiation
DisplayFormatwith the format Chrome wants. It pipes the value to the original property.In the view I doubled the Input for the date and encapsulated the two groups by div's with special classes:
With a function I found on stackoverflow (How can I tell if a browser supports <input type='date'>) I can detect if the actual browser uses date-input:
With the next function I remove the input-blocks I do not need:
In the
$(document).readyfunction I call theswitchForChrome();.At this point it seems to work, but the validation of the date allways failed.
So I add some code to work around (ASP.NET MVC 4 avoid generation of data-val-date for datetime):
And finally it works. For display I use the original property (
Geburtsdatum) so I get the language-specific format and for edit either the original property (IE, Firefox) or the new propertyGeburtsdatumChromeEdit(Chrome, Opera).