Hi,
I've a kendo grid with a delete option for each row. Delete an item and it is removed from the list and the dete from the data context performs successfully. However when I delete another row, it tries to perform the delete of the first deleted row a 2nd time, cant find the entity and throws an error, so the 2nd item is not deleted.
Code as follows -
View
@(Html.Kendo().Grid<OriginGreen.Areas.Portal.Models.DisplayArticleViewModel>() .Name("Article") .Columns(columns => { columns.Bound(p => p.Id).Title("Id").Visible(false); columns.Bound(p => p.Title).Title("Title").Width(100); columns.Bound(p => p.AticleTypeDesc).Title("Article Type").Width(100); ; columns.Bound(p => p.AticleCodeType).Title("Article Type").Visible(false); columns.Bound(p => p.PublishedOn).Format("{0:dd/MM/yyyy HH:mm:ss}").Width(150).Title("Date Published").Width(100); columns.Command(command => command.Destroy()).Width(40); columns.Template(x => { }).ClientTemplate("<a class='k-button k-button-icontext k-grid-EditArticle' href='" + Url.Action("Edit", new { id = "#= Id #" }) + "'>Edit</a>").Width(30); }) .Events(e => e.DataBound("onRowBound") ) .Pageable() .Sortable() .Scrollable() .Filterable(ftb => ftb.Mode(GridFilterMode.Row)) .DataSource(dataSource => dataSource .Ajax() .ServerOperation(false) .PageSize(10) .Batch(true) .Model(model => { model.Id(p => p.Id); model.Field(p => p.Title); }) .Read(read => read.Action("DisplayArticlesRead", "Article").Type(HttpVerbs.Get)) .Destroy(destroy => destroy.Action("ArticleDestroy", "Article").Type(HttpVerbs.Post)) ) )
Server-side -
[AcceptVerbs(HttpVerbs.Post)] //public ActionResult ArticleDestroy([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<DisplayArticleViewModel> articles) public ActionResult ArticleDestroy([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<DisplayArticleViewModel> articles) { if (articles.Any()) { foreach (var article in articles) { // Delete Any Article Attachments first, so as not to leave orphaned records var articleAttachments = _articleRepository.GetArticleAttachments(article.Id); if (articleAttachments.Count > 0) { foreach (var articleAttachment in articleAttachments) { _articleRepository.DeleteAttachment(articleAttachment.AttachmentId); } } _articleRepository.DeleteArticle(article.Id); } } //return Json(articles.ToDataSourceResult(request, ModelState)); return Json(articles.ToDataSourceResult(request, ModelState)); }
I've read up on it and it seems I need to return a success indicator to the grid but I cant work out how to do this in an mvc setup.
Any help greatly appreciated.
Terry.
