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

MVC KendoUI Grid - Issue with Create first time create is called subsequent postback does not work for Delete unless refresh

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean Bornstein
Top achievements
Rank 1
Sean Bornstein asked on 26 Mar 2013, 12:55 PM
Hello all,

Having a strange issue and I can post some sample code if needed.   I have setup the KendoUI grid with .Create, .Update, .Destroy.   Each individually works fine and gets into the method calls and performs the task.  However, once the page loads if I do a create, the insert happens fine, the grid shows my new record at the top of the grid.  This only happens if the chain of events I take is Add New Record calls the create, then if I click the delete button postback does not occur into the delete method.   If I click Edit the Create method gets called again.    If I complete an edit then delete it works fine both methods are called.  The create has the following for example:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Role_Create([DataSourceRequest] DataSourceRequest request, RoleModel role)
{
if (role != null && ModelState.IsValid)
{
DataProvider.Use(s => s.InsertRoles(role.RoleCode, role.RoleDescription));
}

return Json(new[] { role }.ToDataSourceResult(request, ModelState));
}

Now once that occurs the Ajax adds that record it seems.   Then if I click the Delete button on a row, the alert comes up do you want to delete I hit okay.  The row deletes in the grid visually but the call never gets called as I have a break point in my code and the DB is not showing it deleted.   If I click create and create a new record then I click edit, the create method gets called instead of the update so it calls the previous ajax call it seems.   Again this only happens after the first click of the Add New Item that calls the create method.   If I do a create then I manually refresh the page it then works as expected.   It seems also that on the subsequent requests it gets into the previous calls sometimes as well.   Any idea why this would be happening?   Attaching my sample CSHTML and some of the classes to see what I am doing.

1 Answer, 1 is accepted

Sort by
0
Accepted
Sean Bornstein
Top achievements
Rank 1
answered on 26 Mar 2013, 05:16 PM
I figured this out as I had to set the Model.Id to the newly added identity value.  Wish this was mentioned somewhere.
Tags
Grid
Asked by
Sean Bornstein
Top achievements
Rank 1
Answers by
Sean Bornstein
Top achievements
Rank 1
Share this question
or