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

Kendo MVC Grid - Error Event Handle

8 Answers 3500 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Uday
Top achievements
Rank 1
Uday asked on 04 Feb 2015, 07:08 PM
Hi,
Does the Kendo MVC grid handle HTTP 500 errors that thrown during the CRUD operations? The 'error_handler' is fired but no errors are displayed?

Do I have to catch the exceptions and manually add them to the "ModelState' dictionary for them to be displayed to the user using 'error_handler' javascript funtion? See my html markup below.

@(Html.Kendo().Grid<
Province>()
             .Name("ProvinceGrid")
             .Columns(columns =>
             {
                 columns.Bound(l => l.Name).Title("Name");
                 columns.Command(command =>
                 {
                     command.Edit();
                     command.Destroy();
                 }).Width(200);
             })
             .ToolBar(toolbar => toolbar.Create())
             .Editable(editable => editable.Mode(GridEditMode.InLine))
             .Pageable()
             .Scrollable()
             .HtmlAttributes(new {style = "height:450px;"})
             .DataSource(dataSource => dataSource
                 .Ajax()
                 .PageSize(20)
                 .Events(events => events.Error("error_handler"))
                 .Model(model => model.Id(p => p.Id))
                 .Create(update => update.Action("Create", "Province").Data("getCountryId"))
                 .Read(read => read.Action("Read", "Province", new {countryId = Model}))
                 .Update(update => update.Action("Update", "Province"))
                 .Destroy(update => update.Action("Delete", "Province"))
             )
       )

I appreciate your help.

8 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 06 Feb 2015, 01:33 PM
Hello,

Assuming that you are using the "error_handler" from the demos then yes, you should catch the exception and add a ModelState error in order to show the message.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Uday
Top achievements
Rank 1
answered on 06 Feb 2015, 06:48 PM
Thanks Daniel.

Uday
0
John
Top achievements
Rank 1
answered on 01 Mar 2016, 06:37 PM
Is there an example of handling 500 errors somewhere I can reference?  I'm having some problems coming up with a good solution to handle errors that occur during AJAX calls for all the grids in my project which have inline editing.  Having try...catch in all my ActionResults in all my controllers seems like a terrible idea. 
0
Rosen
Telerik team
answered on 03 Mar 2016, 03:13 PM

Hello John,

I'm afraid we do not have such example at hand. However, if you need to handle the controller exceptions in a centralized location you could use controller's OnException method to catch the error and modify the returned result. Something similar to the following:

public void OnException(ExceptionContext filterContext)
{
    if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
    {
        filterContext.ExceptionHandled = true;
        filterContext.Result = new JsonResult
        {
            JsonRequestBehavior = JsonRequestBehavior.AllowGet,
            Data = new
            {
                //create structure similar to the one build from the ModelState by ToDataSourceResult extension method
                Errors = new Dictionary<string, object>() {
                     {
                         "exception",
                         new Dictionary<string, string>() {
                             {"errors", filterContext.Exception.Message}
                         }
                     }
                }
            }
        };
    }
    else
    {
        base.OnException(filterContext);
    }
}

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Neil
Top achievements
Rank 1
answered on 03 Mar 2017, 05:10 PM

I have the following Grid, and for the life of me can't determine what is going on.

@(Html.Kendo().Grid<SOCKETWorx.Site.Models.WorxMenu>()
         .Name("grid_WorxMenus")
         .Columns(columns =>
         {
             columns.ForeignKey(c => c.ParentId, (System.Collections.IEnumerable)ViewData["availableParentMenus"], "Id", "Title").Title("Parent").EditorTemplateName("ParentMenu").HeaderHtmlAttributes(new { style = "text-align:center" }).Width(100);
             columns.Bound(c => c.Title).Width(125).HeaderHtmlAttributes(new { style = "text-align:center" });
             columns.Bound(c => c.Description).Width(125).HeaderHtmlAttributes(new { style = "text-align:center" });
             columns.ForeignKey(c => c.ModuleId, (System.Collections.IEnumerable)ViewData["availableModules"], "Id", "DisplayName").Title("Module").EditorTemplateName("ModuleEditor").HeaderHtmlAttributes(new { style = "text-align:center" }).Width(100);
             columns.Bound(c => c.Display).Width(75).Title("Display").HeaderHtmlAttributes(new { style = "text-align:center" });
             columns.Bound(c => c.Ordering).Width(75).Title("Order").HeaderHtmlAttributes(new { style = "text-align:center" });
             columns.Bound(c => c.Icon).Width(75).Title("Icon").HeaderHtmlAttributes(new { style = "text-align:center" });
             columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
         })
         .ToolBar(toolbar =>
         {
             toolbar.Create().Text("New Menu Item");
         })
         .Editable(editable => editable.Mode(GridEditMode.InLine))
         .Scrollable()
         .Filterable()
         .Groupable()
         .Sortable()
         .HtmlAttributes(new { style = "height:800px;" })
         .DataSource(dataSource => dataSource
             .Ajax()
             .Group(g => g.Add(c => c.ParentId))
             .Sort(s => s.Add(a => a.Ordering))
             .Events(events => events.Error("onGridError"))
             .Model(model => model.Id(p => p.Id))
             .Read(read => read.Action("WorxMenus_Read", "Admin"))
             .Create(create => create.Action("WorxMenus_Create", "Admin"))
             .Update(update => update.Action("WorxMenus_Update", "Admin"))
             .Destroy(destroy => destroy.Action("WorxMenus_Destroy", "Admin"))
         )
       )

 

On any CRUD action, I'm getting the generic 500 error, without it ever reaching the controller. The update action gives me a little more information, [Exception: List is not a valid value for Int32.] However none of my lists use integers, as the primary keys in my database are exclusively guids.

Any help on debugging this further would be most appreciated.

0
Konstantin Dikov
Telerik team
answered on 07 Mar 2017, 08:24 AM
Hi Neil,

You can take a look at the Action methods in the controller in our online demo for the InLine editing and see if there is a difference in your configuration:
If the issue persist you can share the controller code here or open a support ticket and attach a sample, runnable project replicating the issue, so we can debug it on our end.


Best Regards,
Konstantin Dikov
Telerik by Progress
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 visualization (charts) and form elements.
0
Neil
Top achievements
Rank 1
answered on 07 Mar 2017, 05:32 PM

Here's the stack trace from the action. Again I'm not even making it to the Grid events. This is happening when trying to Create.

[NullReferenceException: Object reference not set to an instance of an object.]
   Kendo.Mvc.UI.DataSourceRequestModelBinder.TryGetValue(ModelBindingContext bindingContext, String key, T& result) +109
   Kendo.Mvc.UI.DataSourceRequestModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +120
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +331
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +105
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) +743
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +14
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +343
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +465
   System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +20
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +374
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +16
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +384
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
0
Konstantin Dikov
Telerik team
answered on 09 Mar 2017, 11:08 AM
Hi Neil,

In order for us to be able to investigate this any further, please open regular support ticket and attach a sample project replicating the issue, because from the stack trace of the exception and the Grid configuration it is not clear what could be causing the problem that you are facing.


Best Regards,
Konstantin Dikov
Telerik by Progress
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 visualization (charts) and form elements.
Tags
Grid
Asked by
Uday
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Uday
Top achievements
Rank 1
John
Top achievements
Rank 1
Rosen
Telerik team
Neil
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or