加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在内部OnException(ExceptionContext filterCont

发布时间:2020-12-15 20:55:39 所属栏目:asp.Net 来源:网络整理
导读:情况是这样的: 我找不到获取传递给POST操作方法的viewModel的方法. [HttpPost]public ActionResult Edit(SomeCoolModel viewModel){ // Some Exception happens here during the action execution...} 在控制器的可覆盖的OnException内: protected overrid
情况是这样的:

我找不到获取传递给POST操作方法的viewModel的方法.

[HttpPost]
public ActionResult Edit(SomeCoolModel viewModel)
{
    // Some Exception happens here during the action execution...
}

在控制器的可覆盖的OnException内:

protected override void OnException(ExceptionContext filterContext)
{
    ...

    filterContext.Result = new ViewResult
    {
        ViewName = filterContext.RouteData.Values["action"].ToString(),TempData = filterContext.Controller.TempData,ViewData = filterContext.Controller.ViewData
    };
}

调试代码时,filterContext.Controller.ViewData为null,因为代码执行时发生了异常,并且未返回任何视图.

无论如何,我看到filterContext.Controller.ViewData.ModelState被填充并具有我需要的所有值,但我没有完整的ViewData => viewModel对象可用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读