Skip to main content

MVCxBatchUpdateValues<T, S>.Update Property

Contains a list of data items updated on the client side in batch edit mode.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v23.2.dll

NuGet Package: DevExpress.Web.Mvc5

Declaration

public List<T> Update { get; set; }

Property Value

Type Description
List<T>

An object that stores the list of records that have been updated on the client side.

Remarks

In batch edit mode, user changes are maintained on the client side until an extension sends a callback with the changes to the server side. This callback is handled by an Action in the Controller defined by 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 extension’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.

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());
        }
    }
}
See Also