【问题标题】:Asp.net MVC 3 view engine errorAsp.net MVC 3 查看引擎错误
【发布时间】:2011-09-23 14:31:46
【问题描述】:

我正在尝试在 Application_Error 中进行全局级别的自定义错误处理。

    Exception ex = Server.GetLastError();
    Server.ClearError();
    AssortmentDefinitionLogManager.LogException(ex);
    Context.RewritePath("/Error/Error");
    IHttpHandler httpHandler = new MvcHttpHandler();
    httpHandler.ProcessRequest(Context);

但我得到了这个错误

Error Message - The view '~/Views/Shared/Error' or its master was not found or no view engine supports the searched locations.

我也试过了

        var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
        var redirectUrl = urlHelper.Action("Error", "Error");

        Response.Redirect(redirectUrl);

【问题讨论】:

  • 在~/Views/Shared/或~/Views/Error/目录下是否存在视图“Error”?

标签: asp.net-mvc-3 application-error


【解决方案1】:

创建一个名为 ErrorController 的控制器,并在此控制器内创建一个名为 Error 的操作方法,该方法返回一个 ActionResult(或 ViewResult)。

然后在~/Views/Error/ 下创建一个名为error.cshtml 的视图。

这会解决你的问题。

【讨论】:

    猜你喜欢
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多