MVCxBatchUpdateValues<T, S>.Update Property
Contains a list of grid data items updated on the client side in batch edit mode.
Namespace: DevExpress.Web.Mvc
Assembly: DevExpress.Web.Mvc5.v18.2.dll
Declaration
Property Value
Type | Description |
---|---|
List<T> | A List<T>
|
Remarks
In the batch editing mode, all the end-user changes are maintained on the client side until the Update button is clicked, or all changes are canceled by clicking the Cancel changes button. When an end-user clicks Update, the grid extension sends a callback with user changes (the MVCxBatchUpdateValues<T, S> object) to the server side. This callback is handled by an Action in the Controller, defined using the BatchUpdateRouteValues property. This Action method receives the MVCxBatchUpdateValues<T, S> object as a parameter and allows you to apply all the changes made on the client side to the grid’s data source.
The Update property contains a list of records updated on the client side in batch edit mode.
The code sample below demonstrates how to apply the changes obtained from the client side to the data source.
Controller code (“HomeController”):
using System;
using System.Linq;
using System.Web.Mvc;
using DevExpress.Web.Mvc;
using MyProject.Models;
namespace MyProject.Controllers
{
public class HomeController : Controller
{
// ...
// Apply all changes made on the client side to a data source.
[HttpPost, ValidateInput(false)]
public ActionResult BatchEditingUpdateModel(MVCxGridViewBatchUpdateValues<Customer, object> updateValues)
{
var model = db.Customers;
// Insert all newly added values.
// ...
// Update all edited values.
foreach (var customer in updateValues.Update)
{
if (updateValues.IsValid(customer))
{
try
{
var modelItem = model.FirstOrDefault(it => it.CustomerID == customer.CustomerID);
if (modelItem != null)
{
this.UpdateModel(modelItem);
db.SaveChanges();
}
}
catch (Exception e)
{
ViewBag.EditError = e.Message;
}
}
}
// Delete all values that were deleted on the client side from the data source.
// ...
return PartialView("_GridViewPartial", model.ToList());
}
}
}