This is a migrated thread and some comments may be shown as answers.

Model's Id value is not available in EditorTemplate

1 Answer 725 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chencharao
Top achievements
Rank 1
Chencharao asked on 09 Dec 2015, 03:40 PM

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

1 Answer, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 10 Dec 2015, 12:43 PM
Hello,

Please navigate to the forum thread below, where the same problem is discussed:

http://www.telerik.com/forums/accessing-model-fields-in-editor-templates

Regards,
Milena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Chencharao
Top achievements
Rank 1
Answers by
Milena
Telerik team
Share this question
or