I'm stumped.
I am trying to use Ajax batch editing, but when I go to save changes with a new record, the grid doesn't display the proper json data that is returned.
Here are a few screenshots to show what's happening:
Add a couple records in one batch, this seems to work great.
![]()
Now, if I try and add another record here is what happens:
![]()
It has posted to the database just fine. I have a new line item with Id #35, part id #3, qty 3, and unit price 3, but instead it has duplicated the top record from the grid before the second posting.
Here's the raw json that was returned from the create method:
![]()
So, I don't know what I'm missing. I've poked around but can't seem to pinpoint what is wrong.
Here is my view code:
Here is my controller method:
Any thoughts?
Thanks,
-Sid.
I am trying to use Ajax batch editing, but when I go to save changes with a new record, the grid doesn't display the proper json data that is returned.
Here are a few screenshots to show what's happening:
Add a couple records in one batch, this seems to work great.
Now, if I try and add another record here is what happens:
It has posted to the database just fine. I have a new line item with Id #35, part id #3, qty 3, and unit price 3, but instead it has duplicated the top record from the grid before the second posting.
Here's the raw json that was returned from the create method:
So, I don't know what I'm missing. I've poked around but can't seem to pinpoint what is wrong.
Here is my view code:
@(Html.Kendo().Grid<PoLineItemModel>().Name("grdPoLines") .DataSource(dataSource => dataSource .Ajax() .Model(model => model.Id(m => m.Id)) .Batch(true) .ServerOperation(false) .PageSize(20) .Events(events => { events.RequestEnd("onRequestEnd"); events.Change("onRequestEnd"); }) .Create(create => create.Action("Ajax_CreatePoLines","PoHeaders", new { poid = Model.Id})) .Read(read => read.Action("Ajax_ReadPoLines", "PoHeaders", new { poid = Model.Id })) .Update(update => update.Action("Ajax_UpdatePoLines", "PoHeaders", new { poid = Model.Id })) ) .Columns(columns => { columns.Bound(m => m.PoHeaderId).Visible(false); columns.Bound(m => m.Id); columns.Bound(m => m.PartId); columns.Bound(m => m.Quantity); columns.Bound(m => m.UnitPrice); }) .ToolBar(toolbar => { toolbar.Save(); toolbar.Create(); }) .Navigatable() .Sortable() .Filterable() .Groupable() .Editable(edit => edit.Mode(GridEditMode.InCell)))Here is my controller method:
public ActionResult Ajax_CreatePoLines([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<PoLineItemModel> poItems){ var poid = Int32.Parse(Request.QueryString["poid"]); var ldb = new ShopTrackEntities(); foreach (var newitem in poItems) { var newline = new PoLine { PoHeaderId = poid, PartId = newitem.PartId, Quantity = newitem.Quantity, UnitPrice = newitem.UnitPrice }; ldb.PoLines.Add(newline); } ldb.SaveChanges(); var allitems = GetPoLineItems(poid); var lines = new List<PoLineItemModel>(); foreach (var item in allitems) { var additem = new PoLineItemModel { Id = item.Id, PoHeaderId = item.PoHeaderId, PartId = (int)item.PartId, Quantity = (int)item.Quantity, UnitPrice = (decimal)item.UnitPrice }; lines.Add(additem); } return Json(lines.ToDataSourceResult(request,ModelState));}Any thoughts?
Thanks,
-Sid.