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

grid not refresh after create

4 Answers 1053 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bertha
Top achievements
Rank 1
Bertha asked on 08 Jul 2014, 08:50 PM
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()
%>

4 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 10 Jul 2014, 12:30 PM
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.

 
0
Bertha
Top achievements
Rank 1
answered on 10 Jul 2014, 02:28 PM
Thanks.  Solve my issue.
0
Taffy Lewis
Top achievements
Rank 1
answered on 20 Aug 2019, 01:36 PM
This is so crazy, we have to set the id on creation???
0
Alex Hajigeorgieva
Telerik team
answered on 22 Aug 2019, 07:49 AM
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.
Tags
Grid
Asked by
Bertha
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Bertha
Top achievements
Rank 1
Taffy Lewis
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or