Telerik Grid always returns 0 instead of a value when trying to update grid data

1 Answer 88 Views
Top achievements
Rank 1
Rajesh asked on 09 Aug 2023, 09:10 PM

Hello i am using Oracle Database and have a model  called CableView Model  that i pass to grid  and CableInfoID is my  intended  id for the grid. I have issues updating grid data as always it returning 0 instead of a value.What am i doing wrong?


grid code

                                .Columns(columns =>
                                    columns.Bound(p => p.CableInfoID);
                                    columns.Bound(p => p.CableId).Title("Cable").Width(100);
                                    columns.Bound(p => p.SwitchName).Width(100);
                                    columns.Bound(p => p.Port).Width(100);
                                    columns.Bound(p => p.TechnicianAssigned).Title("TechnicianAssigned").Width(150);
                                    columns.Bound(p => p.AvailableIp).Width(100);
                                    columns.Bound(p => p.SubnetMask).Width(100);
                                    columns.Bound(p => p.Comments).Width(100);
                                    columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
                                .ToolBar(toolbar => toolbar.Create())
                                .Editable(editable => editable.Mode(GridEditMode.PopUp))
                                .Events(ev => ev.Edit("onEdit"))
                                .Events(ev => ev.BeforeEdit("onEdit"))
                                .Events(ev => ev.Cancel("onCancel"))
                                .HtmlAttributes(new { style = "height:430px;" })
                                .DataSource(dataSource => dataSource
                                .Events(events => events.Error("error_handler"))
                                .Model(model =>
                                    model.Id(p => p.CableInfoID);
                                    model.Field(id => id.CableInfoID).DefaultValue(-1);
                            .Create(update => update.Action("Cables_Create", "Home").Data("getData"))
                            .Read(read => read.Action("Cables_Read", "Home").Data("getID"))
                            .Update(update => update.Action("Cables_Update", "Home").Data("getData"))
                            .Destroy(update => update.Action("Cables_Destroy", "Home"))






 public class CableViewModel

        [ScaffoldColumn(false) ]
        public int CableInfoID { get; set; }

        [DisplayName("Cable ID")]
        public string CableId { get; set; }

        [DisplayName("Switch Name")]
        public string SwitchName { get; set; }

        public string Port { get; set; }

        public string ToolID { get; set; }
        //public int ?ToolRecID { get; set; }
        public int ToolRecID { get; set; }

        [DisplayName("Technician Assigned")]
        public string TechnicianAssigned { get; set; }

        [DisplayName("Available IP")]
        public string AvailableIp { get; set; }

        [DisplayName("Subnet Mask")]
        public string SubnetMask { get; set; }

        public string Gateway { get; set; }
        public string Comments { get; set; }



i have  update method as follows ..please ignore other fields as i am returning from view or grid..

Everytime i try to update  the grid row the CableInfoID is 0 

  public ActionResult Cables_Update([DataSourceRequest] DataSourceRequest request, CableViewModel product, int ToolRecID, string toolID, string Empltext)
            if (ModelState.IsValid && product != null)

                // Create a new Product entity and set its properties from the posted ProductViewModel.
                var entity = new DiIpmsCableTeamCableInfo
                    RecordId = product.CableInfoID,
                    CableId = product.CableId,
                    SwitchName = product.SwitchName,
                    Port = product.Port,
                    TechnicianAssigned = Empltext,
                    ToolId = product.ToolID,
                    ToolRecId = ToolRecID,

                // Attach the entity.
                // Change its state to Modified so Entity Framework can update the existing product instead of creating a new one.
                _db.Entry(entity).State = EntityState.Modified;
                // Or use ObjectStateManager if using a previous version of Entity Framework.
                // northwind.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
                // Update the entity in the database.


            // Return the updated product. Also return any validation errors.
            return Json(new[] { product }.ToDataSourceResult(request, ModelState));


In the grid  update method 

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 14 Aug 2023, 02:59 PM

Hi Rajesh,

I would initially like to say a big thank you for adding all the relevant code portions that are currently incorporated on your premises.

I have carefully gone over Grid's component and Model declaration and I managed to conclude that the behavior is due to the inclusion of the [ScaffoldColumn] DataAnnotation. Internally, this will inevitably cause the "CableInfoID" to be prohibited from participating in the editing operations for the Grid.

Thus, I would recommend either omitting the aforementioned attribute. Or, if this option is not feasible provide a "DTO" model that will be used in the Grid model instead.

Alternatively, the Grid component exposes the ability to explicitly induct a custom PopUp template that may hold any arbitrary markup as per your requirements. In the context of your scenario, you can then induct an editor for the CableInfoID field there.

We have a dedicated GitHub example that illustrates such a scenario for the Telerik UI for ASP.NET Core Grid that can be found here:

Here is the full configuration for the custom popup example in particular:

  • View
  • Popup Editor - should be allocated within the "~Views\Shared\EditorTemplates" folder as the Grid will look for the template within this folder location.
  • Model
  • Controller

Please give these suggestions a try and let me know how it works out for you.

Kind Regards,
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Top achievements
Rank 1
commented on 15 Aug 2023, 03:51 PM

Thank You for the details and  running through git hub project with various examples.Thats helps a lot.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question