Last post Oct 25, 2019 03:00 PM by mlightsout
Sep 20, 2019 05:53 PM|mlightsout|LINK
I have an ASP.net MVC 5 website that has a date picker on the form. The culture on the website is set to Polish (pl-PL) which uses a European date format DD.MM.YYYY. I am using datepicker-pl-PL.js for the date picker on my form. The markup on the form
does include the jQuery validation scripts. My problem is when the form is submitted the client side validation says "The field MIX DATE is not in the correct format" but it is in the DD.MM.YYYY format upon submission. I don't have any data annotations set
for that field either, I checked that. I've done some research on the web but nothing has worked. How do I get client side validation to work for this date format?
Sep 25, 2019 10:43 PM|PaulTheSmith|LINK
I would assume that the picker gives you a value of type DateTime. You should pass that DateTime value to the back end, not the string that the user entered.
Can you show some of your code? Maybe we can help more.
Oct 25, 2019 03:00 PM|mlightsout|LINK
If I pass date time of "dd.MM.yyyy hh:mm:ss" from the datepicker it doesn't work either, I get the same error message on the CLIENT side. So I guess the question is how do I get Jquery client side validation to recognize a date based on the culture. It's
as if it only recognizes US dates as valid. I've researched a lot on the web over the last month and I have not found a solution. I looked at using Globalize but I have no idea how to implement it in my ASP.net MVC 5 application; I tried following the example
I currently have this in my web.config which defines my culture (normally this is set to "auto" and I let the browser language dictate the culture but when debugging I'm forcing it to Polish):
<globalization fileEncoding="utf-8" requestEncoding="utf-8" culture="pl-PL" uiCulture="pl-PL" enableClientBasedCulture="true" />
My bundleconfig.cs does include the datepicker-pl-PL.js file but the date picker is not the problem, the date picker is showing the date in the European format as expected so that is working just fine. The issue is when I click the SAVE button to submit
the form the CLIENT side validation is complaining my date is not in the correct format.