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

查看:140
本文介绍了使用DatePicker时,kendoValidator()导致“字段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...

推荐答案

您可以尝试以下方法:

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.

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

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