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

Bulk Update / Save is not working with MVC

4 Answers 316 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Subbiah
Top achievements
Rank 1
Subbiah asked on 11 Jun 2014, 03:09 PM
Hi,

  I am trying to save the modified changes from kendo ui grid, but its not hitting the controller method. Here is my view code,

01.  @(Html.Kendo().Grid<Club.Models.FieldModel>()
02.      .Name("config")
03.      .Columns(columns =>
04.      {
05.          columns.Bound(s => s.Id).Hidden();
06.          columns.Bound(s => s.FieldName).Width(10).Title("Field Name");
07.          columns.Bound(s => s.isVisible).Width(10).Title("Hidden ?");
08.          columns.Bound(s => s.isReadonly).Width(10).Title("Read Only ?");
09.          columns.Bound(s => s.isMultiSelect).Width(10).Title("Single Select ?");
10.          columns.Bound(s => s.isMask).Width(10).Title("Masking ?");
11.          columns.Bound(s => s.MaskLength).Width(10).Title("Mask Length");
12.          /*columns.Command(commands =>
13.          {
14.              commands.Destroy(); // The "destroy" command removes data items
15.          }).Title("Commands").Width(200);*/
16.      })
17.      .ToolBar(toolbar =>
18.      {
19.         // toolbar.Create(); // The "create" command adds new data items
20.          toolbar.Save(); // The "save" command saves the changed data items
21.      })
22.      .Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode
23.      .DataSource(dataSource =>
24.          dataSource.Ajax()
25.            .Batch(true) // Enable batch updates
26.            .Model(model =>
27.            {
28.                model.Id(s => s.Id);
29.                model.Field(s => s.Id).Editable(false);
30.                model.Field(s => s.FieldName).Editable(false);
31.                model.Field(s => s.MaskLength).DefaultValue(2);
32.               
33.            })
34.           // .Create(create => create.Action("Products_Create", "Home"))
35.            .Read(read => read.Action("GetConfig", "Field",new { moduleId = 1 }))
36.            .Update(update => update.Action("ConfigsUpdate", "Field").Type(HttpVerbs.Post))
37.            //.Update(update => update.Action("ConfigsUpdate", "Field"))
38.            .Destroy(destroy => destroy.Action("Products_Destroy", "Home"))
39.            .PageSize(5)
40.      )
41.      .Pageable(pager => pager.PageSizes(new int[] {5, 10, 20}))
42.      .Filterable()
43.      .Sortable()
44.       
45.)

And my update actionmethod in the controller is,

01.[AcceptVerbs(HttpVerbs.Post)]
02.  public ActionResult ConfigsUpdate([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<FieldModel> fieldItems)
03.  {
04.      var entities = new List<FieldModel>();
05.      foreach (var item in fieldItems)
06.      {
07.          var entity = new FieldModel
08.          {
09.              Id = item.Id,
10.              FieldName = item.FieldName,
11.              isVisible = item.isVisible,
12.              isMultiSelect = item.isMultiSelect,
13.              isReadonly = item.isReadonly,
14.              isMask = item.isMask,
15.              MaskLength = item.MaskLength
16.          };
17.      }
18.      return Json(entities.ToDataSourceResult(request, ModelState, item => new FieldModel
19.      {
20.          Id = item.Id,
21.          FieldName = item.FieldName,
22.          isVisible = item.isVisible,
23.          isMultiSelect = item.isMultiSelect,
24.          isReadonly = item.isReadonly,
25.          isMask = item.isMask,
26.          MaskLength = item.MaskLength
27.      }));
28.  }

4 Answers, 1 is accepted

Sort by
0
Subbiah
Top achievements
Rank 1
answered on 12 Jun 2014, 06:12 AM
Hi,

  Please tell me, whats the problem in the above code.
0
CS
Top achievements
Rank 2
answered on 12 Jun 2014, 06:43 AM
Hello Subbiah,
my first guess would be, you might attempt to save fields with no initial values, that would call a "create" and not an "update". Only if you change an existing value "update" is called.
0
Subbiah
Top achievements
Rank 1
answered on 12 Jun 2014, 07:21 AM
Hi Stefan,

  Thanks for the reply, but that is not the root cause for my issue, i changed the order of js library, now its working great. But now i struck up with an another issue, when Id field's duplicates, then those rows are not posted to server in update action. I had done workaround, but i want to know, how it can be solved in a better way.
0
Daniel
Telerik team
answered on 13 Jun 2014, 11:43 AM
Hello,

I am not sure what could be causing the problem. Even if the IDs are the same the records should still be posted to the server. The items will not be posted to the update action if the ID value is the same as the default value in which case the record will be sent to the create action. Could that be the case? If not, then could you provide a runnable sample that replicates this behavior so I can investigate further what exactly goes wrong? 

Regards,
Daniel
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
Subbiah
Top achievements
Rank 1
Answers by
Subbiah
Top achievements
Rank 1
CS
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or