Hi,
I am working on Kendo Grid with MVC.Net. I am using CRUD operations with editor template. I am unable to get the model id value in editor template to figure out if it is a new record or existing record.
Here is my grid configuration which in cshtml file
@(Html.Kendo()
.Grid<TestRecord>()
.Name("Test")
.Columns(columns =>
{
columns.Bound(col => col.Id);
columns.Bound(col => col.Name);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create().Text("Add New Record"))
.Editable(editable => editable
.Mode(GridEditMode.PopUp)
.TemplateName("TestEditor"))
.Sortable()
.DataSource(dataSource =>
{
dataSource
.Ajax()
.ServerOperation(false)
.Model(m =>
{
m.Id(a => a.Id);
m.Field(a => a.Name)
})
.Read(read => read.Action("TestRead", "TestControl", new { id = this.Model.Id }))
.Create(create => create.Action("TestRead", "TestControl"))
;
})
)
My Editor is in separate file names TestEditor.cshtml. I am able to add/edit records without any issues. I need to update only one column if it is existing record. Hence I am hiding the remaining fields (other than the one I am updating) in the editor window. So I was wondering if I can use the model's Id column to figure out if it is a new record or not.
Here is my editor template : TestEditor.cshtml
@model TestRecord
// Render all the columns
@if (this.Model.Id > 0)
{
// only updated related column
}
Regards,
Chen