I have seen this problem in many places, but I cannot find a solution. Therefore, I defined a Kendo grid with CRUD operations that the previous running operations started again. Let's say you delete the X record, and then add the Y record, the create operation starts, and then the delete operation (for X, which was deleted) works again. The same thing if you first create an element and then edit another, edit the second element and then re-run the first create statement and insert a duplicate for the first inserted element. If you turn on with multiple operations, the nightmare happens with all other previous operations that are started and sent to the controller.
My grid:
function InitializeIPAddressesGrid(userID) { selectedUserID = userID; $(".ipAddresses").kendoGrid({ dataSource: IPAdressesDataSource, sortable: { mode: "single", allowUnsort: false }, remove: function (e) { this.refresh(); var canDelete = confirm("Are you sure you want to delete this record?"); if (!canDelete) { e.preventDefault(); } }, height: 420, resizable: true, pageable: { refresh: true, pageSize: 10 }, selectable: "row", toolbar: ["create"], editable:{mode: "inline", confirmation:false} , columns: [{ field: "IpAddress", title: "IP Address" }, { field: "Status", title: "Status" }, { field: "LockedUntil", title: "Locked until", template: "#=kendo.toString(LockedUntil, 'yyyy/MM/dd' )#" }, { command: ["edit", "destroy"], title: " ", width: "180px" } ] }); } var IPAdressesDataSource = new kendo.data.DataSource({ type: "json", serverPaging: true, serverSorting: true, serverFiltering: true, pageSize: 10, //scrollable:false, transport: { read: { url: websiteRootUrl + '/PortalAuthorization/GetIPAddressesList', }, update: { url: websiteRootUrl + "/PortalAuthorization/UpdateIP", dataType: "json", type: 'POST', complete: function (e) { if (e.status != 200) { alert(eval('(' + e.responseText + ')').Message); } } }, create: { url: websiteRootUrl + "/PortalAuthorization/CreateIP", dataType: "json", type: 'POST', complete: function (e) { if (e.status != 200) { alert(eval('(' + e.responseText + ')').Message); } } }, destroy: { url: websiteRootUrl + "/PortalAuthorization/DeleteIP", dataType: "json", type: 'DELETE', complete: function (e) { if (e.status != 200) { alert(eval('(' + e.responseText + ')').Message); } } }, parameterMap: function (options, operation) { if (operation == "update" && options) { return {ipAddress: options.IpAddress , status: options.Status , lockedUntil: kendo.toString(options.LockedUntil, 'yyyy/MM/dd' ), pkey: options.ID, databaseID: selectedDatabaseID }; } else if (operation == "destroy" && options) { return { databaseID: selectedDatabaseID, pkey: options.ID, userIDParam: selectedUserID }; } else if (operation == "create" && options) { return {ipAddress: options.IpAddress , status: options.Status , lockedUntil: kendo.toString(options.LockedUntil, 'yyyy/MM/dd' ), pkey: options.ID, userIDParam: selectedUserID, databaseID: selectedDatabaseID }; } else { options.databaseID = selectedDatabaseID; options.userID = selectedUserID; return options; } } }, schema: { model: { id: "ID", fields: { IpAddress: { type: "string" }, Status: { type: "string" }, LockedUntil: { type: "date" } } }, data: function (data) { return data.Items; }, total: function (data) { return data.TotalCount; } } });
My controllers:
public object UpdateIP(int databaseID, long pkey, string status, string lockedUntil, string ipAddress) { var database = [...]; DynamicDataRepository repository = [...]; string query = "..."; repository.ExecuteNonQuery(query); return new HttpResponseMessage(HttpStatusCode.OK); } public object DeleteIP(int databaseID, long pkey, int? userIDParam) { var database = [...]; DynamicDataRepository repository = [...]; string query = "..."; repository.ExecuteNonQuery(query); return new HttpResponseMessage(HttpStatusCode.OK); } public object CreateIP(int databaseID, long? pkey, string status, string lockedUntil, string ipAddress, int? userIDParam) { var database = [...]; DynamicDataRepository repository = [...]; string query = "..."; repository.ExecuteNonQuery(query); return new HttpResponseMessage(HttpStatusCode.OK); }
Do you have an idea? where did i do something wrong? thanks in advance. Postscript requests in controllers work fine.