Hi,
I have a simple grid with only the Read and Destroy actions defined for the datasource. I also have an error event handler defined. While playing around with this setup, I noticed, that the row is removed as soon as I click the destroy button, even before the controller is called. If an error occures in the controller, my error handler does, what it should, but the grid is not refreshed. Do I have to do that by myself (If so, how do i do this in the error handler?) or did I make a mistake?
My View:
Controller:
Error Handler:
Best regards
Dietmar
I have a simple grid with only the Read and Destroy actions defined for the datasource. I also have an error event handler defined. While playing around with this setup, I noticed, that the row is removed as soon as I click the destroy button, even before the controller is called. If an error occures in the controller, my error handler does, what it should, but the grid is not refreshed. Do I have to do that by myself (If so, how do i do this in the error handler?) or did I make a mistake?
My View:
@(Html.Kendo().Grid<
StorageClasses
>()
.Name("StorageClassesGrid")
.ToolBar(toolbar => toolbar.Template("<
button
id
=
'btnAddSC'
class
=
'k-button'
><
span
class
=
'k-icon k-add'
></
span
></
button
>"))
.Columns(columns =>
{
columns.Command(command =>
{
command.Destroy().Text(" ").HtmlAttributes(new { style = "width:14px;min-width:27px" });
}).Width("40px;");
columns.Bound(p => p.Name);
columns.Bound(p => p.Remark);
})
.Pageable(pager => pager.Refresh(true))
.Sortable()
.Scrollable(s => s.Height("auto"))
.Filterable()
.Resizable(r => r.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(model => model.Id(m => m.ID))
.Read(read => read.Action("GetStorageClassesByLocation", "Locations", new { LocationID = Model.ID }))
.Destroy(destroy => destroy.Action("StorageClass_Delete", "Locations", new { LocationID = Model.ID }))
.Events(e => e.Error("onGridError"))
)
.Events(e => e.Remove("onGridRowRemove").DataBound("resizeTabs"))
)
Controller:
[HttpPost]
public ActionResult StorageClass_Delete([DataSourceRequest] DataSourceRequest request, long? LocationID, StorageClasses StorageClass)
{
Exception exception;
if (StorageClass != null && LocationID != null)
{
try
{
if (ModelState.IsValid)
{
// delete entity in database
var result = _db.StorageClass_Delete(
LocationID.HasValue ? LocationID.Value : 0,
StorageClass.ID,
ClientName,
"WEB",
UserName,
out exception);
if (exception != null)
{
AddException(exception);
}
// check database action result
if (result != null && result.ErrorID == 0)
{
// database action successful
return Json(new[] { StorageClass }.ToDataSourceResult(request, ModelState));
}
else
{
ModelState.AddModelError("StorageClass_Delete", result.ErrorMessage);
return Json(new[] { StorageClass }.ToDataSourceResult(request, ModelState));
}
}
}
catch (Exception ex)
{
AddException(ex);
ModelState.AddModelError("StorageClass_Delete", ex.Message);
return Json(new[] { StorageClass }.ToDataSourceResult(request, ModelState));
}
}
ModelState.AddModelError("StorageClass_Delete", "Parameter Fehler.");
return Json(new[] { StorageClass }.ToDataSourceResult(request, ModelState));
}
Error Handler:
function onGridError(e) {
var txt = "";
$.each(e.errors, function (propertyName) {
txt = txt +this.errors + " ";
});
$("#lblStatus").text(txt);
$("#lblStatus").css('color', 'red', 'font-weight ', 'bold');
}
Best regards
Dietmar