【问题标题】:Kendo UI Datepicker with custom format of "MMMyy"自定义格式为“MMMyy”的 Kendo UI Datepicker
【发布时间】:2019-04-23 21:24:54
【问题描述】:

我正在尝试为绑定模型字段创建剑道日期选择器,但格式为“MMMyy”,而不是完整日期。用户需要看到其格式为“MMMyy”日期。 P>

这是我的模型字段:

[DisplayFormat(DataFormatString = "{0:MMMyy}")]
public DateTime? DeliveryMonthDate { get; set; }

和这里是我在视图中的形式dateicker:

@Html.LabelFor(model => model.DeliveryMonthDate, new { @class = "caption text-bold" }, true)
@(Html.Kendo().DatePickerFor(model => model.DeliveryMonthDate)
.Name("DeliveryMonthDate")
.Start(CalendarView.Year)
.Depth(CalendarView.Year)
.Format("MMMyy")
.ParseFormats(new string[] { "MMMyy" })
)
@Html.ValidationMessageFor(model => model.DeliveryMonthDate)

当用户从日期选择器中选择月份时,该值会以 MMMyy 格式正确显示(例如 Nov18)。 但是,由于它不是有效的日期格式,所以会出现验证错误(此字段必须是日期)。

如何验证在日期选择器中输入了正确的月份和年份,格式为“MMMyy”?

【问题讨论】:

    标签: asp.net-mvc validation kendo-ui kendo-datepicker


    【解决方案1】:

    自定义格式也将用于解析输入。 https://docs.telerik.com/kendo-ui/api/javascript/ui/datepicker/configuration/format

    解决方案可以在日期选择器中显示自定义格式,但具有用于提交有效日期格式的隐藏字段。隐藏字段可以在更改事件上更新。 https://docs.telerik.com/kendo-ui/api/javascript/ui/datepicker/events/change

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      相关资源
      最近更新 更多