我有我的數據源可爲空的DateTime屬性 - ExpectedReceiptDate,我在網格中實現內聯編輯:劍道UI電網在線日期編輯,從劍道UI傳遞日期ASP.NET導致無效的ModelState
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
transport: {
//setup transport
},
schema:
{
data: 'Data', total: 'Total', errors: 'Errors',
model:
{
id: 'Id',
fields: {
Id : { editable: false, type: 'number' },
Name : { editable: false, type: 'string' },
ExpectedReceiptDate : {
editable: true,
format: "{0: dd/MMM/yyyy}",
nullable: true,
type: 'date'
}
}
}
},
requestEnd: function(e) {
if (e.type == 'update') {this.read();}
},
serverFiltering: true,
serverSorting: true
},
editable: {
mode: "inline"
},
columns: [
{
field: "Id",
title: "ID"
},{
field: "Name",
title: "Name"
},{
field: "ExpectedReceiptDate",
title: "Date",
editor: DateEditor,
},
{
title: " ",
command: ["edit"],
width: 200
}
]
});
});
編輯器很簡單:
function DateEditor(container, options) {
$('<input required name="' + options.field + '"/>')
.appendTo(container)
.kendoDatePicker({format: "dd/MMM/yyyy"});
}
編輯的行拿起日期例如,當24 /月/ 2017年我得到了一個錯誤
:
無效的模型狀態ExpectedReceiptDate,值「(日期)FLE標準時間」是無效的ExpectedReceiptDate
我已嘗試添加自定義驗證該字段:
function ExpectedReceiptDateValidator(input){
if (input.is("[name='ExpectedReceiptDate']") && input.val() != "") {
try {
var date = kendo.parseDate(input.val(), "dd/MMM/yyyy");
if(!date)
return false;
} catch (err) { return false;}
console.log('res', true);
}
return true;
}
驗證通過後,輸入的日期值被很好地解析到Date obj中,但模型狀態錯誤仍然存在。 什麼導致模型狀態錯誤?
感謝,是requestEnd不需要 –