I'm trying to implement an error handling mechanism in my MVC project. I'm looking for a way to display the error message to the user on the same page. I've tried -
returning JavaScript(..) - However, this does not work as I'm calling the action through an ActionLink and not Ajax.I cannot call it through Ajax as error may have been generated even when the page loads for the 1st time.
returning Content(..) - This doesn't show an alert either
I do this in a catch block -
public ActionResult Index()
{
try
{
//something that generates an exception
}
catch(Exception e)
{
//show an alert with the error through JS
}
}
Is there any way of executing javascript to display an error to the user without using an Ajax call to execute the action?