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?
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With