【发布时间】:2014-04-08 03:39:09
【问题描述】:
我正在处理 Base 控制器中的错误。我需要在剃刀视图中显示存储在临时数据中的错误,异常类型。我该怎么做?
基本控制器代码
protected override void OnException(ExceptionContext filterContext)
{
// if (filterContext.ExceptionHandled)
// return;
//Let the request know what went wrong
filterContext.Controller.TempData["Exception"] = filterContext.Exception.Message;
//redirect to error handler
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(
new { controller = "Error", action = "Index" }));
// Stop any other exception handlers from running
filterContext.ExceptionHandled = true;
// CLear out anything already in the response
filterContext.HttpContext.Response.Clear();
}
Razor 查看代码
<div>
This is the error Description
@Html.Raw(Html.Encode(TempData["Exception"]))
</div>
【问题讨论】:
标签: c# asp.net-mvc razor error-handling