Question

I have a controller named ErrorController with an action Index.

I am capturing exceptions from other controllers namely HomeController and storing the exceptions as shown below in a model named ExceptionDetails

public class ExceptionDetail
  {
    public string message { get; set; }
    public string details { get; set; }
  }

Once an exception is caught I will store the it in the above shown model and want to send it to the action Index of the controller ErrorController.

How can I do that

I tried the following but it didn't work.

catch (System.Exception exception)
  {
    exceptionDetail.details = exception.ToString();
    exceptionDetail.details = exception.Message.ToString();
    return RedirectToAction("Index", "Error", new { exception = exceptionDetail });
  }

The Index action is shown below and I have a strongly typed view for Index too.

 public ActionResult Index(ExceptionDetail exceptionDetail)
  {
    return View(exceptionDetail);
  }

Thanks for any help in advance.

Was it helpful?

Solution

your method signature is :

public ActionResult Index(ExceptionDetail exceptionDetail)

so your RedirectToAction should define a parameter "exceptionDetail' :

return RedirectToAction("Index", "Error", exceptionDetail);

OTHER TIPS

return RedirectToAction("Index", "Error", exceptionDetail);

By this way I can use the model properties at thea ction Index of controller ErrorController

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top