Showing exception message from controller class to view page
asp.net-mvc-3
Solution
If you want to show the error message on the same view:
[HttpPost]
public ActionResult Add(Model model)
{
try
{
// some code...
return RedirectToAction("Success");
}
catch (SomeException ex)
{
ModelState.AddModelError("", ex.Message);
return View(model);
}
}
and inside your `Add.cshtml` view you could use the ValidationSummary helper to display the error message:
@Html.ValidationSummary()
Problem
I have defined a method in try catch block in HomeController.cs in my MVC3 Razor project. Now please tell how wil I show this exception message on my view page?