在剃刀中个性化错误视图

时间:2013-06-11 08:18:51

标签: c# asp.net .net asp.net-mvc razor

我有一个Asp.net mvc4应用程序,我想在其中个性化异常页面

<customErrors mode="On" defaultRedirect="~/Views/Shared/Error.cshtml" ></customErrors>

错误页面:

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Erreur";
}
<p>Take it easy</p>
<hgroup class="title">
    <h1 class="error">Erreur.</h1>
    <h2 class="error">Une erreur s'est produite lors du traitement de la requête.</h2>

</hgroup>

当抛出异常时,我得到一个不同的视图:

view

出现此错误的原因是什么?

1 个答案:

答案 0 :(得分:3)

您需要错误网址指向错误页面的网址。不要像.cshtml那样。如果您的错误页面的操作方法(返回Error.cshtml中定义的视图)是“CustomError”并位于“ErrorController”中,那么您将添加以下内容:

<customErrors mode="On" defaultRedirect="Error/CustomError" >
</customErrors>
相关问题