This example demonstrates how to enable the grid's batch edit mode and use a controller action method to update grid data.
In batch edit mode, the grid allows users to modify data in batches and send them to the server in one request. Set the grid's SettingsEditing.Mode property to Batch
to enable the grid's batch edit functionality.
settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
To enable batch edit operations, add a controller action method. This method obtains a MVCxGridViewBatchUpdateValues object as a parameter. Use the object's Update, Insert, and DeleteKeys properties to get infomation about modified, inserted, and deleted grid rows.
public ActionResult BatchEditingUpdateModelPerson(MVCxGridViewBatchUpdateValues<Person, int> batchValues) {
foreach(var person in batchValues.Update) {
if(batchValues.IsValid(person))
PersonsList.UpdatePerson(person);
else
batchValues.SetErrorText(person, "Correct validation errors");
}
foreach(var person in batchValues.Insert) {
if(batchValues.IsValid(person))
PersonsList.AddPerson(person);
else
batchValues.SetErrorText(person, "Correct validation errors");
}
foreach (var personID in batchValues.DeleteKeys) {
PersonsList.DeletePerson(personID);
}
return PartialView("GridViewPartial", PersonsList.GetPersons());
}
- HomeController.cs (VB: HomeController.vb)
- PersonsList.cs (VB: PersonsList.vb)
- _GridViewPartial.cshtml
(you will be redirected to DevExpress.com to submit your response)