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

Why is my grid calling create for every row of data?

2 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 17 Feb 2016, 09:40 PM

Why is my grid calling "CreateFooBar" for every row of data when delete and update are submitted? It's probably something stupid but I can't see it.

 

   @(Html.Kendo()
          .Grid<FooBarViewModel>()
          .Name("FooBarGrid")
          .Sortable()
          .Scrollable()
          .Filterable()
          .Resizable(g => g.Columns(true))
          .Columns(columns =>
          {
              columns.Command(command =>
              {
                  command.Edit();
                  command.Destroy();
              }).Width(150);
              columns.Bound(g => g.Id).Hidden();
              columns.Bound(g => g.Name).Title("Name").Width(200);
              columns.Bound(g => g.FooBarNumber).Title("FooBar<br />Number").Width(200);
              columns.Bound(g => g.CreatedBy).Width(100).Title("Created By");
              columns.Bound(g => g.CreatedDate).Width(100).Title("Created Dt");
              columns.Bound(g => g.ModifiedBy).Title("Modified By").Width(100);
              columns.Bound(g => g.ModifiedDate).Width(100).Title("Modified Dt");
          })
          .DataSource(dataSource => dataSource.Ajax()
              .Model(model =>
              {
                  model.Id(m => m.Id);
                  model.Field(p => p.CreatedBy).Editable(false);
                  model.Field(p => p.CreatedDate).Editable(false);
                  model.Field(p => p.ModifiedDate).Editable(false);
                  model.Field(p => p.ModifiedBy).Editable(false);
              })
              .Batch(false)
              .PageSize(25)
              .ServerOperation(false)
              .Read(read => read.Action("GetFooBars", "FooBar"))
              .Create(update => update.Action("CreateFooBar", "FooBar"))
              .Update(update => update.Action("UpdateFooBar", "FooBar"))
              .Destroy(update => update.Action("DeleteFooBar", "FooBar"))
              .Events(ev => ev.RequestEnd("onSave"))
              .Events(events => { events.Error("onError"); })
          )
          .ClientDetailTemplateId("collectionTemplate")
          .Events(ev => ev.Edit("onEdit"))
          .ToolBar(toolbar =>
          {
                  toolbar.Create().Text("Add FooBar");   
          })
          
          .Editable(editable => editable.Mode(GridEditMode.InLine))
                  .Pageable(pager => pager
                        .Input(true)
                        .Numeric(true)
                        .Info(true)
                        .PreviousNext(true)
                        .Refresh(true)
                        .PageSizes(new int[5] { 25, 50, 100, 200, 500 })
                    )
                    .ColumnMenu()
    )

2 Answers, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 17 Feb 2016, 10:08 PM
For posterity is was because the Model Id was not getting set, so I guess the grid sees every line as new. Did this used to throw a javascript error?
0
Alexander Valchev
Telerik team
answered on 19 Feb 2016, 10:08 AM
Hi Marc,

Your observation is correct, the issue will occur when the ID is not assigned because in this case the error is considered as new. A missing ID never resulted in JavaScript errors, there is no reason to obligate the developer to assign IDs, in some cases, for example when the Grid is not editable, the ID is not mandatory.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or