custom HandleErrorAttribute
i want to display all errors on the same page (without redirecting/changing page content) where it wa开发者_开发知识库s happened (e.g. javascript alert) and i think that the error-page could load like PartialView. i try to create custom HandleErrorAttribute, but it's not working:
public class CustomHandleErrorAttribute : HandleErrorAttribute
{
public string PartialViewName { get; set; }
public override void OnException(ExceptionContext filterContext)
{
var result = new PartialViewResult();
result.ViewName = PartialViewName;
filterContext.Result = result;
}
}
Try something like this:
protected override void OnException(ExceptionContext filterContext)
{
filterContext.ExceptionHandled = true;
this.View("Error").ExecuteResult(this.ControllerContext);
}
More info (including how to make it obey customErrors=RemoteOnly) can be found here:
http://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html
精彩评论