简体   繁体   English

Kendo网格行在插入时重复

[英]Kendo grid row duplicating on insert

I have a Kendo grid containing data rows where if two new rows are added consecutively, the first row that was added into the grid will have a duplicate record inserted into the SQL db table. 我有一个Kendo网格,其中包含数据行,如果连续添加两个新行,则添加到网格中的第一行将有一条重复记录插入SQL db表中。 I've seen other posts where the suggestion has been to use the "complete" event on the create event: 我看过其他帖子 ,建议在create事件上使用“ complete”事件:

transport: {
        read: UrlBase + "getAll",
        create: {
            url: UrlBase + "create",
            dataType: "jsonp",
            complete: function (e) {
                $("#grid").data("kendoGrid").dataSource.read();
            }
        },

The issue is, in my code, I'm using model binding to send the data to the server side and the grid structure needs to be maintained as well: 问题是,在我的代码中,我使用模型绑定将数据发送到服务器端,并且网格结构也需要维护:

<div class="k-pane">
        @{
            Html.Kendo().Grid(Model)
            .Name("exampleGrid")
            .Columns(columns =>
            {
                columns.Select().Width(60);
                columns.Bound(c => c.exampleUniqueID).Hidden(true);
                columns.Bound(c => c.example1ID).Hidden(true);
                columns.Bound(c => c.example2ID).Hidden(true);
                columns.Bound(c => c.example1CD).EditorTemplateName("exampleDropDown").Width(300);
                columns.Bound(c => c.EffectiveDate).Format("{0:MM/dd/yyyy}").EditorTemplateName("EffectiveDatePicker");
                columns.Bound(c => c.EndDate).Format("{0:MM/dd/yyyy}").EditorTemplateName("EndDatePicker");
                columns.Bound(c => c.SortOrder);
                columns.Bound(c => c.AddedBy);
                columns.Bound(c => c.AddedOn);
                columns.Bound(c => c.UpdatedBy);
                columns.Bound(c => c.UpdatedOn);

            })

            .ToolBar(toolbar =>
            {
                toolbar.Create().Text("Add");
                toolbar.Save().SaveText("Save");

            })
            .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
            .Scrollable()
            .Sortable()
            .Events(e => e.SaveChanges("exampleGrid_onSaveChanges"))
            .DataSource(datasource => datasource
                           .Ajax()
                           .Model(model =>
                               {
                                   model.Id(d => d.exampleUniqueID);
                                   model.Field(f => f.AddedBy).Editable(false);
                                   model.Field(f => f.AddedOn).Editable(false);
                                   model.Field(f => f.UpdatedBy).Editable(false);
                                   model.Field(f => f.UpdatedOn).Editable(false);
                               }
                            )
                           .ServerOperation(false)
                           .Read(read => read.Action("ControllerAction", "ControllerName"))
                           .Create(create => create.Action("ControllerAction_Create", "ControllerName").Data("exampleGrid_onAdditionalData"))
                           .Update(update => update.Action("ControllerAction_Create", "ControllerName"))
                           .Destroy(delete => delete.Action("ControllerAction_Delete", "ControllerName"))
                           .Events(e => e.Error("exampleGridDS_onError"))
                        )
            .Render();

        }
    </div>

Because the grid uses the arrow syntax in the event method calls (for read, update, create, etc) and because the "complete" event is used in the JSON format definition of data source, how can the "complete" event be used in the above grid? 由于网格在事件方法调用(用于读取,更新,创建等)中使用箭头语法,并且由于在数据源的JSON格式定义中使用了“ complete”事件,因此如何在事件源中使用“ complete”事件?上面的网格? If it can't be, how can the duplicates be prevented from be inserted in to the sql table? 如果不能,如何防止重复项插入sql表?

Use requestEnd event for dataSource. 将requestEnd事件用于dataSource。 It'll call after the transport methods. 它将在传输方法之后调用。

.Events(events => events.RequestEnd("add_a_javascript_method"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM