Skip to content

Instantly share code, notes, and snippets.

@christopherhouse
Created December 17, 2013 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherhouse/8006698 to your computer and use it in GitHub Desktop.
Save christopherhouse/8006698 to your computer and use it in GitHub Desktop.
using System;
using System.Web.Mvc;
using ThirteenDaysAWeek.Mvc4CustomErrorPage.Web.Models;
namespace ThirteenDaysAWeek.Mvc4CustomErrorPage.Web.Controllers
{
public class ErrorController : Controller
{
public ActionResult Index(int statusCode, Exception exception, bool isAjaxRequet)
{
Response.StatusCode = statusCode;
// If it's not an AJAX request that triggered this action then just retun the view
if (!isAjaxRequet)
{
ErrorModel model = new ErrorModel {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);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment