简体   繁体   中英

Kendo Ajax Delete in a grid

Using Kendo Grid and MVC 4

In my controller when it errors out I send a error message:

    return this.Json(new DataSourceResult
        {
            Errors = "my custom error"
        });

The error is nicely displayed, however the item is visually removed from the grid, even though not from the data source. Refreshing the grid puts it back.

How do I have the grid not delete a record visually when it receives an error in the delete method?

To pass error message from controller to view , you need to use ModelState, see below:

ModelState.AddModelError("Delete", "my custom error");
return Json(ModelState.ToDataSourceResult());

You also can use an empty string for the key:

ModelState.AddModelError(string.Empty, "my custom error");
return Json(ModelState.ToDataSourceResult());

Update

Without your code, it's hard to imagine where the problem is exactly. You can try below code and see how it works for you . But maybe the problem comes from your Kendo grid code.

   var model = new YourBuildingModel();
   model = GetModelList();
   //
   ModelState.AddModelError(string.Empty, "my custom error");
   var buildingData = (new List<YourBuildingModel> {model}).ToDataSourceResult(request, ModelState);
   return Json(buildingData, JsonRequestBehavior.AllowGet);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM