asp.net mvc - Executing JavaScript from an Action that returns ActionResult -


I am trying to implement the error handling system in my MVC project. I am looking for a way to show the error message to the user on the same page. I have tried -

- However, this does not work because I am calling the action through the ActionLink and not Ajax. I can not call it through Ajax because the error may load when the page loads for the first time.

- This does not show a warning

I do this in a catch block -

  Public Action Index () {Try {// Some that generate an exception} Cache (Exception E) {// Show a warning with error via JS}}   

Is there a way to execute javascript? An error to the user without using an Ajax call?

You can do something like

  hold (exception e) {ViewBag.Error = "Error:" + E. Toasting (); } See Return ();   

In your view

  & lt;% if (ViewBag.Error! = Null) {%> & Lt; Script type = "text / javascript" & gt; Warning ('<% = ViewBag.Error%>';); & Lt; / Script & gt; & Lt;%}% & gt;    

Comments