protected ActionResult ErrorResult(HttpStatusCode statusCode, string message = null, Exception exception = null) { var code = statusCode.ChangeType <string>(); var isDebug = HttpContext.IsDebuggingEnabled; var errorViewModel = new ErrorViewModel(statusCode, errorMessage: message); Response.StatusCode = errorViewModel.Code; if (!Request.IsAjaxRequest()) { return(View(nameof(ErrorsController.Index), errorViewModel)); } ModelState.AddModelError(code, errorViewModel.Message); return(JsonError(ModelState)); }