Reputation: 68740
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?
Upvotes: 1
Views: 851
Reputation: 15188
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);
Upvotes: 1