【发布时间】:2014-12-08 11:35:05
【问题描述】:
我正在开发一个 MVC 5 互联网应用程序,并且有一个关于将 object 传递给共享 view 的问题。
我在共享文件夹中有一个名为CustomError.cshtml 的view。此view 具有以下模型类型:@model CanFindLocation.ViewModels.CustomErrorViewModel
如何将CanFindLocation.ViewModels.CustomErrorViewModel 类型的对象从protected override void OnException(ExceptionContext filterContext) 中的protected override void OnException(ExceptionContext filterContext) 函数传递给view?
这是我的代码:
protected override void OnException(ExceptionContext filterContext)
{
Exception e = filterContext.Exception;
if (e is HttpRequestValidationException)
{
filterContext.ExceptionHandled = false;
customErrorViewModel = customErrorService.GetDefaultCustomError(customErrorType, "Test message.");
RedirectToAction("CustomError", customErrorViewModel);
}
}
没有显示view,而是调用了以下函数:
protected void Application_Error(object sender, EventArgs e)
提前致谢。
【问题讨论】:
-
@user373648:Application_Error 抛出了什么异常?
标签: redirect asp.net-mvc-5 asp.net-mvc-viewmodel asp.net-mvc-views onexception