0

似乎如果控制器内部发生异常,视图引擎将不会转到预期的视图,即使“异常”被捕获在 try-catch 块中?

或者我在这里遗漏了一些东西:

public ActionResult MyController(int? param1, DateTime? param2)
{
    MyModel model = new MyModel();
    try
    {
        model = new MyModel();

        //AN ERROR HAPPENS HERE (so the code goes to catch the Exception):
        model.Connection.Initialize();
    }
    catch (Exception ex)
    {
        ViewBag.ErrorMessage = ex.Message;
    }
    //when I put a break point I get to this following line, however, "MyView" is never displayed!?
    return PartialView("MyView", model);
}
4

1 回答 1

1

之后,您可能会在您认为的某个地方遇到另一个异常。查看浏览器页面上显示的堆栈跟踪并修复它。

于 2014-01-20T18:03:12.807 回答