1
votes

I use http://bootstrap-datepicker.readthedocs.org/en/release/ for datepicker with bootstrap.

    [DisplayName("Date Start")]
    [DataType(DataType.Date)]
    public DateTime? DateFrom { get; set; }


$('.datepicker').datepicker({
    format: "mm/dd/yyyy",
    autoclose: true,
    clearBtn: true
});

@Html.TextBoxFor(m => m.DateFrom, new { @class = "form-control datepicker", @placeholder = "Start Date" })
@Html.ValidationMessageFor(m => m.DateFrom)

Today date is 10/06/2014. When i choose date 10/13/2014 i see message "The value '10/13/2014' is not valid for Date Start." while date 10/12/2014 is OK.

Where is mistake?

1
.NET is probably interpreting 10/13/2014 as the 10th day of the 13th month of 2014, which is invalid. It seems that it is expecting dates in dd/mm/yyyy format instead of mm/dd/yyyy. - Cᴏʀʏ
@Cory, Oh, thanks. Yes, this helps! - demo
Maybe have a quick read through: weblogs.asp.net/melvynharbour/mvc-modelbinder-and-localization. If fixing the globalization settings in your app doesn't work, you may need to write a custom model binder. - Cᴏʀʏ

1 Answers

0
votes

it's related to cultures.

I had the same problem and solved it by using Globalize library.

  • use nuget to add Globalize 0.1.3 libray to your project.

  • then include the files globalize.js and globalize.cultures.js

  • then add this code to your custom Js file:

    $.validator.methods.date = function (value, element) {
    return this.optional(element) || Globalize.parseDate(value, "MM/dd/yyyy") !== null;
    }