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
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
Uday
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);
}
}
Rosen
Telerik
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.
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
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
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