0
爲什麼不在編輯字段上的編輯器模板上顯示網格驗證? 我不明白爲什麼不讀數據註釋。 對不起壞英語...爲什麼不在編輯器模板上顯示kendo ui網格驗證
起初,我創建了劍道電網這樣的:
<div id="grid">
@(Html.Kendo().Grid<CardView>()
.Name("Grid")
.Columns(x =>
{
x.Bound(c => c.CardID).Title("Card Nm.");
x.Bound(c => c.ExpirationDate).Format("{0:dd/MM/yyyy}");//.EditorTemplateName("KendoDatePicker");
x.Command(cmd =>
{
cmd.Edit();
}).Title("Edit");
})
.BindTo(Model)
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(x => x.CardID);
})
.ServerOperation(true)
.Read(read => read.Action("Index", "Home"))
.Events(events => events.Error("error_handler"))
.Update(update => update.Action("Update", "Home"))
.Editable(editable =>editable.Mode(GridEditMode.InLine)))
</div>
下面是它的JavaScript使用在數據源事件錯誤:
<script>
function error_handler(e, status) {//Klaidu isvedimas
if (e.errors) {
var message = "Error:\n";
var grid = $('#GrdKendo').data('kendoGrid');
var gridElement = grid.editable.element;
var validationMessageTemplate = kendo.template(
"<div id='#=field#_validationMessage' " +
"class='k-widget k-tooltip k-tooltip-validation " +
"k-invalid-msg field-validation-error' " +
"style='margin: 0.5em;' data-for='#=field#' " +
"data-val-msg-for='#=field#' role='alert'>" +
"<span class='k-icon k-warning'></span>" +
"#=message#" +
"<div class='k-callout k-callout-n'></div>" +
"</div>");
$.each(e.errors, function (key, value) {
if (value.errors) {
gridElement.find("[data-valmsg-for=" + key + "],[data-val-msg-for=" + key + "]")
.replaceWith(validationMessageTemplate({ field: key, message: value.errors[0] }));
gridElement.find("input[name=" + key + "]").focus();
}
});
grid.one("dataBinding", function (e) {
e.preventDefault(); // cancel grid rebind
});
}
}
當我創建我的視圖模型(驗證CardID工作,但不工作expirationDate w HICH使用編輯模板):
public class CardView
{
[Required(ErrorMessage = "Card Expiration Date")]
public virtual string CardID { get; set; }
[UIHint("DatePicker")]
[Required(ErrorMessage = "Card Expiration Date")]
public virtual DateTime ExpirationDate { get; set; }
}
我在查看\共享\ EditorTemplates編輯器中創建模板**的位置,名稱** DatePicker.cshtml:
@model DateTime?
@(Html.Kendo()
.DatePicker()
.Name(ViewData.ModelMetadata.PropertyName.ToString())
.Format("{0:dd/MM/yyyy}"))
因此,如何讀取數據annotacion在編輯器模板字段? 數據annotacions在不使用編輯器模板的字段上完美工作