This is a migrated thread and some comments may be shown as answers.

Multiple deletes/trying to perform first delete again....

2 Answers 287 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 13 Jul 2017, 10:36 AM

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.

 

2 Answers, 1 is accepted

Sort by
0
Terry
Top achievements
Rank 1
answered on 14 Jul 2017, 09:38 AM

Could really do with some help with this. I've tried a number of different approaches now and nothing will work.

I tried firing the following on the .Remove grid event -

 

function refreshList_Remove(e) {
    //alert("Refreshing_R");
    $('#Article').data('kendoGrid').dataSource.read();
    $('#Article').data('kendoGrid').refresh();
    //alert("Refreshed_R");
 
}

 

Again, no luck.

I've also tried the inline editing option here - inline delete with no success.

This is incredibly frustrating.

 

 

0
Stefan
Telerik team
answered on 17 Jul 2017, 05:58 AM
Hello Terry,

From the provided code it seems that the deleted item is not returned to the Grid from the controller.

Please check the expected format in the CRUD article of the DataSource:

http://docs.telerik.com/kendo-ui/framework/datasource/crud#destroy-remote

Also, the Ajax editing page can be helpful in this case:

http://docs.telerik.com/aspnet-mvc/helpers/grid/editing/ajax-editing

Additionally, we have different runnable examples with CRUD operations, where it can be observed how the controller should be set:

https://github.com/telerik/kendo-examples-asp-net

In general, I can suggest inspecting the response from the server once a delete operation is initiated, and observe if there is a difference between the response and the shown format in the documentation.

If additional assistance is needed, please send a fully runnable example, as the issue can be caused by a custom factor which we are overlooking at this moment.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Grid
Asked by
Terry
Top achievements
Rank 1
Answers by
Terry
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or