Model's Id value is not available in EditorTemplate

2 posts, 0 answers
  1. Chencharao
    Chencharao avatar
    1 posts
    Member since:
    Apr 2015

    Posted 09 Dec 2015 Link to this post

    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

  2. Milena
    Admin
    Milena avatar
    224 posts

    Posted 10 Dec 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top