5

I been struggeling with this problem for two days now and have still not found the solution... I have added a datepicker to my website using this tutorial: http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx

Everything works except for the validation. I keep getting the error "Please enter a valid date". I have changed everything in my solution to "dd-MM-yyyy" and added globalization culture="da-DK" uiCulture="da-DK"

to my web.config. I still dosent work. Keep getting the error. Should I maybe changemy model class? The date I want to validate:

    [DataType(DataType.Date)]
    public DateTime DateOfBooking { get; set; }

Tried with:

    $('#formatdate').change(function () {
        $('#datpicker').datepicker("option", "dateFormat", "dd-mm-yy");
    });

and:

$(document).ready(function () {
function getDateYymmdd(value) {
    if (value == null)
        return null;
    return $.datepicker.parseDate("dd-mm-yy", value);
}
$('.date').each(function () {
    var minDate = getDateYymmdd($(this).data("val-rangedate-min"));
    var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
    $(this).datepicker({
        dateFormat: "dd-mm-yyyy",  // hard-coding uk date format, but could embed this     as an attribute server-side (based on the current culture)
        minDate: minDate,
        maxDate: maxDate
    });
});
});

Tried many different solutions but nothing seems to work. Cant figure out if the problem is in the mvc or jquery. Someone please help :) Thanks!

2
  • Have you tried to manually test parseDate, just by putting a validate date in there and seeing if it works. Commented Oct 15, 2011 at 9:53
  • No I havent. This is my first time working with jquery and its a little confusing :) Not sure how the validate works and where it goes on. Commented Oct 17, 2011 at 16:41

1 Answer 1

4

It's the jquery.validate plugin which doesn't recognize this format. I would recommend you the following blog post. You could use the globalize plugin in order to set the preferred culture for client side validation.

Sign up to request clarification or add additional context in comments.

2 Comments

Its a little hard understanding the links you suggested since im not used to working with jquery. Could you give a few more clues? :)
Okay... after a few more hours it seems like im making a little progress. When I select a date everything works. Even the validate... until i change the date. Then I get the message "Please select a valid date". I have two date fiels and it seems like its a little random for when the date is valid or not. Very strange... Any guess for why its like that??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.