kendoValidator() 在使用 DatePicker 时导致“字段 xxx 必须是日期"错误 [英] kendoValidator() causes “The field xxx must be a date” error when using DatePicker

查看:26
本文介绍了kendoValidator() 在使用 DatePicker 时导致“字段 xxx 必须是日期"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MVC5 应用程序选择dd/MM/yyyy"格式的日期会导致 字段 xxx 必须是日期" 错误.另一方面,如果我在下面注释 kendoValidator() 行,错误已经消失,但在这种情况下,我无法执行客户端验证,因此我想使用 kendoValidator.以下是与此控件相关的代码部分.

Im my MVC5 application selecting date in "dd/MM/yyyy" format causes "The field xxx must be a date" error. On the other hand, if I comment kendoValidator() line as below the error has gone, but in that case I cannot perform client side validation and for this reason I want to use kendoValidator. Here are the code sections related to this control.

实体:

[Required(ErrorMessage = "Required field")]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }


查看:

...    
<script src="~/Scripts/kendo/2014.3.1119/cultures/kendo.culture.de.min.js"></script>
<script src="~/Scripts/kendo/2014.3.1119/messages/kendo.messages.de-DE.min.js"></script>

<script>
    $(function () {
        $("form").kendoValidator(); //This line cause the error...
    });
</script>

@Html.LabelFor(m => m.StartDate )
    @(Html.Kendo().DatePickerFor(m => m.StartDate)
    .Animation(true)
    .Culture("de-DE")
    .Footer(false)
    .Format("dd/MM/yyyy")
    .Value(DateTime.Today) 
 )


实体或视图是否有任何缺失或错误的定义?即

Is there any missing or wrong definition on Entity or View? i.e.

[DataType(DataType.Date)]

预先感谢您的帮助...

Thanks in advance for your help...

推荐答案

你可以试试这个作为可能的解决方案:

You can try this as a possible solution:

1) 如果您想将 de-DE 文化应用于整个站点,则可以添加:

1) If you want to apply the de-DE culture to the entire site then you could add:

<script type="text/javascript">
    kendo.culture("de-DE");
</script>

将文化替换为您要应用的文化,并确保您已将适当的文化脚本添加到页面.

Substituting the culture for the one you want to apply and also ensuring you have added the appropriate culture script to the page.

2) 接下来您可以尝试将您想要的日期格式添加到控件允许的日期格式parseFormats"中.

2) The next thing you could try is add the date format you want to the allowed date formats "parseFormats" for the control.

可以这样做:

  @(Html.Kendo().DatePickerFor(m => m.StartDate)
                .Format("dd/MM/yyyy")
                .ParseFormats(new List<string>()               
                              {
                                "dd/MM/yyyy", 
                                "dd/MM/yy",
                                "dd MMM yyyy" 
                              })
   )

这些通常是我处理日期和验证的方式.

These are generally the ways that I go about handling the dates and validating.

这篇关于kendoValidator() 在使用 DatePicker 时导致“字段 xxx 必须是日期"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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