Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP MVC OneException发送异常数据以查看_C#_Asp.net Mvc - Fatal编程技术网

C# ASP MVC OneException发送异常数据以查看

C# ASP MVC OneException发送异常数据以查看,c#,asp.net-mvc,C#,Asp.net Mvc,我正在重写我的控制器OneException方法 protected override void OnException(ExceptionContext filterContext) { if (filterContext.ExceptionHandled) { return; } filterContext.Result = new ViewResult {

我正在重写我的控制器OneException方法

    protected override void OnException(ExceptionContext filterContext)
    {
        if (filterContext.ExceptionHandled)
        {
            return;
        }
        filterContext.Result = new ViewResult
        {
            ViewName = "ErrorPage",
        };
        filterContext.ExceptionHandled = true;
    }
这让我毫不费力地看到了我的观点。但是,我也希望能够将异常消息发送到视图。大概是这样的:

ViewBag.Message = filterContext.Exception.Message;
在我看来:

@model System.Web.Mvc.HandleErrorInfo

@{
ViewBag.Title = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<h2 class="text-danger">Error message: @ViewBag.Message</h2>

你把
ViewBag.Message=filterContext.Exception.Message放在哪里了?你到底遇到了什么问题?你没有看到异常信息吗?我已经更新了操作。结果我犯了个错误。
    protected override void OnException(ExceptionContext filterContext)
    {
        if (filterContext.ExceptionHandled)
        {
            return;
        }

        var ex = filterContext.Exception ?? new Exception("No further information exists.");

        ViewBag.Message = ex.Message;
        filterContext.Result = View("ErrorPage");

        filterContext.ExceptionHandled = true;
    }