public ActionResult Code(int?id) { int statusCode = id.HasValue ? id.Value : 500; ViewBag.ReturnUrl = Request.UrlReferrer; ErreurModel model = new ErreurModel { HttpStatusCode = statusCode }; return(View(model)); }
public ActionResult Index(int statusCode, Exception exception, bool isAjaxRequet) { Response.StatusCode = statusCode; ViewBag.ReturnUrl = Request.UrlReferrer; // If it's not an AJAX request that triggered this action then just retun the view if (!isAjaxRequet) { ErreurModel model = new ErreurModel { HttpStatusCode = statusCode, Exception = exception }; return(View(model)); } else { // Otherwise, if it was an AJAX request, return an anon type with the message from the exception var errorObjet = new { message = exception.Message }; return(Json(errorObjet, JsonRequestBehavior.AllowGet)); } }