选择日期后日期格式不正确

时间:2016-03-21 13:51:02

标签: kendo-ui

我正在使用(k-format =“dd / MM / yyyy”)设置kendo-date-picker的日期格式,因此,在选择日期之后,格式不受尊重。我尝试使用(k-options =“dateTimePickerOptions”)制作

  

$ scope.dateTimePickerOptions = {format:“dd / MM / yyyy”}

它有效,但在将数据发送到服务器之前,我检查了范围内的数据,console.log返回“无效日期”。

这是我的完整代码:

  

输入名称=“数据”kendo-date-picker ng-model =“item.Data”   k-ng-model =“dateObject”style =“width:100%;” placeholder =“选择一个   date“k-options =”dateTimePickerOptions“k-parse-formats   =“['yyyy-MM-ddTHH:mm:sszzz']”required />

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

试试这个

<script>
    jQuery.extend(jQuery.validator.methods, {
        date: function (value, element) {
            return this.optional(element) || kendo.parseDate(value, "dd/MM/yyyy") != null;
        }
    });

</script>

查看

@{
    ViewBag.Title = "Home Page";
}
@model DatePickerValidation.Models.ViewModel

@using (Html.BeginForm())
{
    @( 
        Html.Kendo().DatePickerFor(model => model.MyDate).Format("dd/MM/yyyy")
        .ParseFormats(new List<string>()
                        {
                        "dd/MM/yyyy",
                        "dd/MM/yy",
                        "dd MMM yyyy"
                        })
        .HtmlAttributes(new { @class = "k-datetimepicker" })
    )
    @Html.ValidationMessageFor(model => model.MyDate)

    <input type="submit" value="Submit" />
}

视图模型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DatePickerValidation.Models
{
    public class ViewModel
    {
        public DateTime MyDate { get; set; }
    }
}
相关问题