Created
December 17, 2013 15:26
-
-
Save christopherhouse/8006698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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