JQuery的日期选择不会与英国的日期字符串发布 [英] JQuery Datepicker Will not post with UK date string

查看:110
本文介绍了JQuery的日期选择不会与英国的日期字符串发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关,如果这个问题是显而易见的,但我想不出为什么它突然不工作的道歉。我已经只要我能记住工作正常​​jQuery的日期选择器,但突然间,当我尝试提交表单的日期选择器是在日期选择器会重新出现,就像我提交日期无效。我一直在使用code的以下行已经设置我的约会英国风格:

Apologies for if the question is obvious but I can't figure out why it is suddenly not working. I have a jquery datepicker that has been working fine as long as I can remember, but all of a sudden, when I try to submit the form that the datepicker is on the datepicker reappears as though the date I am submitting is invalid. I have already set my date to 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 setup the datepicker in my view like this:

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

我觉得这事被要求选择在美国的格式(如将提交一个有效的美国日期(MM / DD / YYYY)而不是英国格式datestring,尽管它在JavaScript中设置。

I think that something is requiring the datestring selected to be in US format (as it will submit a valid us date (mm/dd/yyyy) but not the UK format, even though it has been set in the javascript.

我失去了一些东西明显?谁能告诉我我在做什么错在这里?

Am I missing something obvious? Could anyone tell me what I'm doing wrong here?

我不知道,如果它是必要的,但该日期选择器是上这样创建表单:

Am not sure if it is necessary but the form that the datepicker is on is created like this:

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

PS。该datestring实际工作和职位没有在Firefox中的一个问题,但不是在Chrome浏览器

PS. The datestring actually works and posts without a problem in Firefox but not in Chrome

任何帮助AP preciated

Any help appreciated

编辑:

问题消失了,当我关闭不显眼JS验证:

The problem goes away when I disable the unobtrusive js validation:

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

我有一种感觉,这是一件与此有关,并试图remoing的[必需]和[数据类型(DataType.Date)从型号标注但这并没有这样的伎俩。

I had a feeling it was something to do with this and tried remoing the [Required] and [DataType(DataType.Date)] from the model annotation but this didn't do the trick.

不知道如何离开这个不显眼的js的,以及有英国日期字符串的工作不错,但我越来越转向写形式比,甚至与内置的东西,这似乎从来没有打扰我自己的JavaScript验证到任何东西更复杂的不是必要的验证检查工作..

Not sure how to leave the unobtrusive js in as well as have the uk date string working ok, but am more and more turning to write my own javascript validation for forms than to even bother with the built in stuff, which never seems to work for anything more complicated than a 'required' validation check..

推荐答案

谷歌搜索给了很多有关本地化/全球化asp.net MVC 3的验证结果。

a google search gave a lot of results relating to localizing/globalizing asp.net mvc 3 validation.

在这篇文章中特别可能将要发生什么:

this article in particular might be on to something:

<一个href=\"http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx\" rel=\"nofollow\">http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx

向下滚动到:全球化不显眼的jQuery验证

scroll down to: "Globalized jQuery Unobtrusive Validation"

在回答这个问题可能会有所帮助:
<一href=\"http://stackoverflow.com/questions/7438754/localizing-jquery-validation-with-asp-net-mvc-3\">Localizing jQuery验证与asp.net MVC 3

the answer to this question might help as well: Localizing jquery validation with asp.net mvc 3

jQuery的可以覆盖不同的验证函数,像这样:

jQuery allows you to override the different validation functions like so:

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

您可以为日期验证器做这样的事情,并运行对一个有效的英国日期正则表达式。

you could do something like this for the date validator, and run it against a regEx for a valid UK date.

这篇关于JQuery的日期选择不会与英国的日期字符串发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆