[英]Kendo dateTimePickerFor sending NULL or 01/01/0001 00:00 to controller
視圖工作正常,我可以看到datetimepicker但是當我單擊提交時,datetime字段為空(如果可為空)或01/01/0001 00:00如果不可為空。
視圖
<div class="form-group">
@Html.LabelFor(model => model.LaycanStartDate, htmlAttributes: new { @class = "control-label col-md-12" })
<div class="col-md-10">
@Html.EditorFor(model => model.LaycanStartDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LaycanStartDate, "", new { @class = "text-danger" })
</div>
</div>
<script>
$(function () {
$.validator.methods.date = function (value, element) {
var date = moment(value, "DD/MM/YYYY HH:mm", true).format("DD/MM/YYYY HH:mm");
return this.optional(element) || moment(date, "DD/MM/YYYY HH:mm", true).isValid();
}
});
</script>
模型
[Display(Name = "LaycanStartDate", ResourceType = typeof(Resources.Resources))]
[DataType(DataType.DateTime)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy HH:mm}")]
public DateTime LaycanStartDate { get; set; }
DateTime.cshtml
@model DateTime?
@(Html.Kendo().DateTimePickerFor(m => m).HtmlAttributes(new { style = "width: 100%; max-width: 280px", title = "datetimepicker"}))
因此,我最終能夠解決這個問題的唯一方法是刪除控制器上的綁定[Bind(....
沒有它,它允許值通過,控制器可以處理格式
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.