本场日期必须在镀铬MVC日期 [英] The field date must be a date in mvc in chrome

查看:140
本文介绍了本场日期必须在镀铬MVC日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个简单的MVC4互联网应用,这使得一些项目添加到的类别。

I'm doing a simple MVC4 Internet application, which allows to add some items to the categories.

下面是我到目前为止已经完成。

Here is what i've done so far.

我在MVC视图一个datepicker。在日期选择器的脚本是这样的。

I've a datepicker in mvc view. The script for the datepicker is like this.

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
    $(function () {
        $('#dtItemDueDate').datepicker({
            dateFormat: 'dd/mm/yy',
            minDate: 0
        });
    });
</script>

我的模型属性:

        [DisplayName("Item DueDate")]
        [Required]
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}",ApplyFormatInEditMode = true)]
        [DataType(DataType.DateTime)]
        public DateTime? dtItemDueDate { get; set; }
        public char charCompleted { get; set; }

在我看来,我已经做到了这一点:

and in my view i've done this:

@Html.TextBoxFor(m => m.dtItemDueDate)
@Html.ValidationMessageFor(m => m.dtItemDueDate)

错误是这样的:

The field Item DueDate must be a date.

奇怪的是,它确实在IE和Mozilla的工作,但在Chrome中亘古不变的工作。

The strange this is that it does work in IE and mozilla, but doesnot work in Chrome.

我发现了那么多帖子,但没有人帮助

I found many posts on SO, but none of them help

任何意见/建议吗?

推荐答案

编者注:这个答案是不再有效,因为jQuery的1.9(2013年)的 $浏览器方法已被删除

Editor note: This answer is no longer valid, as of jQuery 1.9 (2013) the $.browser method has been removed

根据这个帖子这是一个已知的怪癖基于WebKit的浏览器。

According to this post it's a known quirk with Webkit-based browsers.

一个解决办法是通过查找功能日期修改 jquery.validate.js :函数(值,元素)并且把这种code它:

One solution is to modify jquery.validate.js by finding the function date: function (value, element) and put this code in it:

if ($.browser.webkit) {
    //ES - Chrome does not use the locale when new Date objects instantiated:
    var d = new Date();
    return this.optional(element) || !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
}
else {
    return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
}

这篇关于本场日期必须在镀铬MVC日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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