grid not refresh after create

5 posts, 1 answers
  1. Bertha
    Bertha avatar
    95 posts
    Member since:
    Aug 2012

    Posted 08 Jul 2014 Link to this post

    If I create and then immediately update, it will not have ID and treat the update as new insert and will show error message of "javascript runtime error: unable to get property 'ID' of undefined or null reference."

    If I create and then immediately delete, same error message and it will not delete the data as it has no new inserted id.

    But I can update or delete if the grid is refreshed by refreshing the web page.  What did I miss?

    ​ <%: Html.Kendo().Grid<zProvince>()
    .Name("GridProvince")
    .Columns(columns =>
    {
    columns.Bound(o => o.ProvinceName).Title("Name");
    columns.Bound(o => o.empgroupName).Title("empgroupName");
    columns.Bound(o => o.ID).Hidden();
    columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
    })
    .ToolBar(commands => commands.Create())
    .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
    .DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.ID))
    .Read(read => read.Action("GetProvince", "Admin"))
    .Create(create => create.Action("CreateProvince", "Admin"))
    .Update(update => update.Action("UpdateProvince", "Admin"))
    .Destroy(destroy => destroy.Action("DestroyProvince", "Admin"))
    )
    .Events(events => events
    .Change("change"))
    .Selectable(s => s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single))
    .Scrollable()
    .Pageable()
    %>
  2. Answer
    Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 10 Jul 2014 Link to this post

    Hi Bertha,

    As you may know it is required that the controller action responsible for saving the newly created entries to return the updated entity's id. This way the DataSource will be notified that the particular entry is saved and its status should be changed from new. Therefore, please verify that this requirement is met. You can find a step-by-step tutorial on configuration of Grid editing in this help article. Also you may review the controller code of this online demo.

    Regards,
    Rosen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Bertha
    Bertha avatar
    95 posts
    Member since:
    Aug 2012

    Posted 10 Jul 2014 in reply to Rosen Link to this post

    Thanks.  Solve my issue.
  4. Taffy Lewis
    Taffy Lewis avatar
    10 posts
    Member since:
    Apr 2019

    Posted 20 Aug 2019 in reply to Rosen Link to this post

    This is so crazy, we have to set the id on creation???
  5. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1078 posts

    Posted 22 Aug 2019 Link to this post

    Hi, Guy,

    To distinguish between new and existing models, the data source checks if the item id has the default value for its type - for example a model with numeric id and a value of 0 will be considered as new. 

    So anytime there is a change in a model, if it has no id/ id with default value, the grid data source will send it to the Create operation. If the model has an id, this means it is an existing item, so it will send it to the Update operation.

    So in the context of plain MVC, to edit a model, you would need it to have an Id, otherwise how would you know from the database, which model is needed to pass to the view?



    In case you had something else in mind that I have misunderstood, please elaborate.

    Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top