Question

And Read, Create, Update, Destroy works fine when working with only one row at a time.

But, when i try to add two Customer's the EditingPopup_Create is called three times. One for the first row, and two for the second row... If i add more than two rows the same pattern follows. The EditingPopup_Create method is run as many times as the count of it's customer....

Current implementation is like this:

        @(Html.Kendo().Grid<CustomerModel>()
              .Name("grid")
              .Columns(columns =>
              {
                  columns.Bound(p => p.Name);
                  columns.Bound(p => p.ContactPerson);
                  columns.Bound(p => p.ContactPersonEmail);
                  columns.Bound(p => p.ContactPersonPhone);
                  columns.Bound(p => p.MainPhoneNumber);
                  columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
              })
              .ToolBar(toolbar => toolbar.Create())
                      .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("CustomerPopUpTemplate"))
              .Pageable()
              .Sortable()
              .Scrollable()
              .HtmlAttributes(new {style = "height:500px;"})
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .PageSize(10)
                  //.Events(events => events.Error("error_handler"))
                  .Model(model => model.Id(p => p.Id))
                  .Read(read => read.Action("EditingPopup_Read", "CustomerManagement"))
                  .Create(update => update.Action("EditingPopup_Create", "CustomerManagement"))
                  .Update(update => update.Action("EditingPopup_Update", "CustomerManagement"))
                  .Destroy(destroy => destroy.Action("EditingPopup_Destroy", "CustomerManagement"))
              )
              )

This is probably a newbie mistake, but i cant seem to figure out why this would happen. In my opinion the wiring of the grid should only call the methods once per instance.

Explanation would be greatly appreciated :)

Was it helpful?

Solution

When you perform the save on create are you changing the id associated with the item created?

I suspect what you are doing is not changing the id from what is being provided and grid treats this as another create.

So when you are saving your item back to the database set the id to the database generated or how ever you are generating it and you should see it not doing the second call.

Showing the controller code will help as well to answer it.

Make sure you are returning the model back to the view so that it updates the id associated with it via the json.

Eg

Return json( new { model }.todatasourceresult(request, modelState))

OTHER TIPS

Found a post that answered my question and filled out the question a bit more too...

Kendo UI Grid posting back already Inserted Rows again

A way of explaining it is that if the Id of an object is 0 the grid thinks it's a new row. If it's a new row it thinks it has to insert it. If the value of the Object/Row in the grid is not updated when the row is added, it will try to re-add it because it thinks it does not exist.

I hope this could help anyone out there... :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top