1

I am currently adding exception management inside of our application.

In the application I have a layout that basically shows a news section that is rendered via @Html.Action("news") so far when an exception occurs I can show an error message on the news section saying "well it crashed" but it's not quite the best appeal...

Is it possible to detect it at the parent level and redirect to an error page if a child action encountered an exception?

Erick
  • 5,969
  • 10
  • 42
  • 61
  • Having a similar problem http://stackoverflow.com/questions/10759789/how-to-properly-handle-child-action-exceptions...some info there regarding child actions that may help. – Rich Jun 01 '12 at 19:26

2 Answers2

1

This is what I did. Got this from a similar type of question on SO (not sure which one).

public ActionResult TabInfo(int id, string tab)
    {
        try
        {
            var viewModel = _viewModelManager.GetViewModel(tab, id);

            ViewBag.Jobid = id;
            ViewBag.Tab = tab;

            return PartialView(string.Format("~/Views/{0}/Index.cshtml", tab), viewModel);
        }
        catch (Exception e)
        {
            return View("ErrorChildAction");
        }

    }

ErrorChildAction view

@model System.Web.Mvc.HandleErrorInfo

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
 <head>
  <title></title>
 </head>
 <body>
 <!-- Redirect to an error page in the application root -->
 <script type="text/javascript">
     window.location.href = '@Url.Content("~/400.htm")';
 </script>
</body>

HTH

Rich
  • 1,895
  • 3
  • 26
  • 35
0

This post does what you are looking for. On a application level, it catches exceptions and you can choose what to do with them

ASP.NET MVC Custom Error Handling Application_Error Global.asax?

Community
  • 1
  • 1
Chris Woolum
  • 2,854
  • 20
  • 20