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

Return Error Message to Grid

3 Answers 2265 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 09 Oct 2014, 08:10 AM
How can I return a Custom error for a Grid Operation.

E.g.: If the database delete is not possible show a popup that something is gone wrong.

Controller Method:
[HttpPost]
public ActionResult DestroyEmploymentStatus([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]List<EmploymentStatusViewModel> employmentStatuses)
{
    if (employmentStatuses.Any())
    {
        foreach (var esvm in employmentStatuses)
        {
            var es = db.EmploymentStatuses.Find(esvm.Id);
 
            db.EmploymentStatuses.Remove(es);
            db.SaveChanges();
        }
    }
 
    return Json(employmentStatuses.ToDataSourceResult(request, ModelState));
}

regards

3 Answers, 1 is accepted

Sort by
-1
Accepted
Rosen
Telerik team
answered on 13 Oct 2014, 06:04 AM | edited on 26 Jul 2022, 11:43 AM
Hi Oliver,

You can add the error to the ModelState errors collection. The ToDataSource extension method will serialize the errors in the response and on the server you will be able to get the error in the DataSource error event. More detailed information can be found in this helps article.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Ralph
Top achievements
Rank 1
commented on 25 Jul 2022, 07:45 AM

dead link
Ivan Danchev
Telerik team
commented on 26 Jul 2022, 11:44 AM

The link has been updated with a valid one. Thank you for pointing this out.
0
Debi
Top achievements
Rank 1
answered on 05 Oct 2017, 07:25 PM
But-- what if I ALSO need to return the total row count for server side paging?
0
Stefan
Telerik team
answered on 09 Oct 2017, 10:10 AM
Hello, Debi,

The ToDataSourceResult method should automatically return the total number of items in the response. This can be observed in our demo, by paging the Grid and checking the response in the network tab:

http://demos.telerik.com/aspnet-mvc/grid



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