【发布时间】:2015-07-30 22:25:35
【问题描述】:
我有一个 Kendo 网格,它具有自定义编辑按钮和一个工具栏,可让您添加新的。
编辑/新建功能仅使用一个模板。
如何判断我是处于“编辑”模式还是“新建”模式。
我的代码(剑道网格):
@(Html.Kendo().Grid(Model.OtherBreeds)
.Name("grdOtherBreeds")
.HtmlAttributes(new { @class = "grid" })
.Columns(columns =>
{
columns.Bound(c => c.OrganizationName);
columns.Bound(c => c.Prefix);
columns.Bound(c => c.Name);
columns.Bound(c => c.MemberId);
columns.Template(e => { })
.ClientTemplate(KendoTemplates.ActionColumn.WithEdit().WithDelete().Get())
.Visible(true)
.Title(Resources.Actions)
.Width(Constants.GridCommandColumnWidth);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50) //? standard page size when grid is only UI element on screen?
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.OrganizationName);
model.Field(p => p.Prefix);
model.Field(p => p.Name);
model.Field(p => p.MemberId);
})
)
.Events(e => e.DataBound(KendoEventHandlers.DataBound.WithNoData(Resources.NoOtherBreedsForCustomer).Get()))
.Sortable()
.Pageable()
.Filterable()
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("OtherBreedTemplate").Window(w => w.Width(500).Title("Add Other Breed")))
.ToolBar(toolbar =>
{
toolbar.Template(KendoTemplates.Toolbar.WithAdd("Add Other Breed").Get());
})
)
【问题讨论】:
-
在添加模式下您的 Id=0 / null 吗??
-
是的,我试过用 JS 检查,但它似乎不起作用。我有一个函数可以在模板中获取 Id 的值,但它总是记录 null。
-
有一个
Edit事件,您可以在显示弹出窗口之前捕获表单数据,应该有一个e.model.isNew()可以检查 -
添加和编辑的 ID 是否为空?它应该是一个实数,用于编辑和 null 或 0 或“”,具体取决于添加的数据类型。
标签: javascript c# asp.net-mvc kendo-ui kendo-grid