JQuery datepicker will not publish with english date string

Sorry if the question is obvious, but I can’t understand why it suddenly does not work. I have a jquery datepicker that works fine as far as I remember, but all of a sudden, when I try to submit a form that datepicker is on datepicker, it appears as if the date I am submitting is invalid. I already set the date in uk style using the following line of code:

    <script type="text/javascript">
    $(document).ready(function () {
        $('.date').datepicker({ dateFormat: "dd/mm/yy", minDate: 0 });

    }); 
    </script>

And I configure the datepicker in my view as follows:

@Html.TextBox("DateDue", "", new { @class = "date" })

I think something requires the selected datestring to be in US format (since it will send a valid date (mm / dd / yyyy), but not in the British format, even if it was set in javascript.

Am I missing something obvious? Can someone tell me what I'm doing wrong here?

, , , datepicker, :

@using (
    Html.BeginForm(
        Html.BeginForm(
            "Create",
            "Task",
            FormMethod.Post,
            new { id = "taskCreateForm" }
        )
    )
)

PS. Datestring Firefox, Chrome

EDIT:

, js:

<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"
        type="text/javascript"></script>

, , [Required] [DataType (DataType.Date)] , .

, js, uk, JavaScript , , , - , "" .

+5
3

google , / asp.net mvc 3. .

, , :

http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx

: " jQuery"

: jquery asp.net mvc 3

jQuery :

 $.validator.methods.number = function (value, element) {
     return !isNaN($.parseFloat(value));
 }

- regEx .

+2

dateFormat, javascript ( ..) :

$('.datepicker').datepicker({dateFormat:'yy-mm-dd'});
+2

Try using altFormat instead!

altFormat: "dd/mm/yy",      

This works for me :)

EDIT: try this on JSFiddle http://jsfiddle.net/adover/BRfcK/

+1
source

All Articles