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

Grid datasource create event fired twice

2 Answers 1007 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DevGuy
Top achievements
Rank 1
DevGuy asked on 29 Aug 2013, 12:43 AM
I am using the popup feature of kendoui grid to add/edit a record. The kendoui version that I am using is 2013.2.823. I find that whenever I click the "update" button to create/edit a record the create event is fired twice (see attached image). Any help would be much appreciated.

Soure Code:

@(Html.Kendo().Grid<GroupModel>()
           .Name("grid")
               //.HtmlAttributes(new{style="display:block"})
           .ToolBar(toolbar => toolbar.Create())
           .EnableCustomBinding(false)
           .PrefixUrlParameters(false)
           .AutoBind(true)
               //.Events(e => e.DataBound("grid_DataBound"))
           .Editable(editable => editable.Mode(GridEditMode.PopUp).DisplayDeleteConfirmation(true).CreateAt(GridInsertRowPosition.Top))
               //.Events(e=>e.Edit("grid_onEdit"))
           .Pageable(p => p.Enabled(true).PageSizes(new[] { 10, 20, 30 }).Refresh(true).PreviousNext(true).ButtonCount(4).Info(true).Numeric(true))
           .Navigatable(n => n.Enabled(true))
           .Resizable(r => r.Columns(true))
           .Scrollable(s => s.Height("auto"))
           .Selectable(s => s.Enabled(false).Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
           //.ClientDetailTemplateId("template")
           //.RowAction(row => { })
           .Sortable(sorting =>
           {
               sorting.SortMode(GridSortMode.SingleColumn);
               sorting.Enabled(true);
           })
           .Filterable(filterable => filterable
                           .Extra(true)
                           .Operators(operators => operators
                                           .ForString(str => str.Clear()
                                                                   .StartsWith("Starts with")
                                                                   .EndsWith("Ends with")
                                                                   .Contains("Contains")
                                                                   .IsEqualTo("Is equal to"))
                                           .ForNumber(num => num.Clear()
                                                                   .IsEqualTo("Is equal to")
                                                                   .IsGreaterThan("Is greater than")
                                                                   .IsGreaterThanOrEqualTo("Is greater than or equal to")
                                                                   .IsLessThan("Is less than")
                                                                   .IsLessThanOrEqualTo("Is lesss than or equal  to"))
                                           .ForDate(date => date.Clear()
                                                                   .IsEqualTo("Is equal to")
                                                                   .IsGreaterThan("Is after")
                                                                   .IsGreaterThanOrEqualTo("Is after or equal to")
                                                                   .IsLessThan("Is before")
                                                                   .IsLessThanOrEqualTo("Is before or equal to"))
                                           ))
 
           .Columns(columns =>
               {
                   //columns.Bound(p => p.PROV_GRP_ID).Visible(false).Width(100);
                   columns.Command(command => { command.Edit(); }).Width(75);
                   columns.Bound(p => p.PROV_GRP_KEY).Visible(true).Width(50);
                   columns.Bound(p => p.GroupName).Width(150);
                   columns.Bound(p => p.ContactFirstName).Width(120);
                   columns.Bound(p => p.ContactLastName).Width(120);
                   columns.Bound(p => p.ContactTitle).Width(100);
                   columns.Bound(p => p.PhoneNumber).Width(100);
                   columns.Bound(p => p.StreetAddress1).Width(150);
                   columns.Bound(p => p.StreetAddress2).Width(100);
                   columns.Bound(p => p.City).Width(150);
                   columns.Bound(p => p.State).Width(50);
                   columns.Bound(p => p.Zip).Width(50);
                   columns.Bound(p => p.Email).Width(150);
                   columns.Bound(p => p.IsDeleted).Width(50);
                   //columns.Bound(p => p.IsDeleted).ClientTemplate("#kendo.template($('#tmplActionMenu').html())#").HeaderTemplate(p => "Action").Width(100);
               })
                  .DataSource(dataSource => dataSource
                       .Ajax()
                       .ServerOperation(true)
                       .PageSize(20)
                       .Batch(false)
                       .AutoSync(false)
                       .Events(events => events.Error("grid_dataSource_OnError"))
                       .Model(m =>
                       {
                           m.Id(p => p.PROV_GRP_KEY);
                           //m.Field(f => f.PROV_GRP_KEY).Editable(false);
                           //m.Field(f => f.IsDeleted).Editable(false);
                       })
                       .Read(read =>
                           {
                               read.Action("GetGroups", "Roster");
                               read.Type(HttpVerbs.Post);
                           })
                       .Create(create =>
                           {
                               create.Action("CreateGroup", "Roster");
                               create.Type(HttpVerbs.Post);
                           })
                       .Update(update =>
                           {
                               update.Action("UpdateGroup", "Roster");
                               update.Type(HttpVerbs.Post);
                           })
                       .Destroy(destroy =>
                           {
                               destroy.Action("DeleteGroup", "Roster");
                               destroy.Type(HttpVerbs.Post);
                           }))
             )

2 Answers, 1 is accepted

Sort by
0
Femi
Top achievements
Rank 1
answered on 21 Oct 2017, 12:12 AM
I am having this same issue. Any ideas why my Create action of the grid is posting twice to my controller?
0
Stefan
Telerik team
answered on 24 Oct 2017, 11:20 AM
Hello, Femi,

In general, such issue can occur if the ID is not correctly set in the dataSource or the Grid does not receive a success callback with the new records.

Please check if the first request receives a success callback with the ID before the second request is made.

I can suggest checking our article for the CRUD operations as it contains the required steps when binding the Grid:

https://docs.telerik.com/kendo-ui/framework/datasource/crud

https://docs.telerik.com/aspnet-mvc/helpers/grid/editing/ajax-editing

If the issue still occurs, please provide a fully runnable example and I will gladly assist further.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
DevGuy
Top achievements
Rank 1
Answers by
Femi
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or