0

I've got a Bootstrap modal window that has an ActionLink to call a method in the controller and to do stuff:

@Html.ActionLink("Process Data", "ProcessData", "Controller", null, new { @class = "btn btn-success" })

However, I want to do it so that when the user presses this ActionLink (the Save Changes button), I want the modal to close automatically after they press it.

Is there a way to directly call another jQuery/Javascript method once ProcessData finishes executing? This also isn't a POST method if it matters.

LOL. NO.
  • 577
  • 1
  • 6
  • 33
  • You may write Js function onclick event to close the model. How are you calling controller method? ajax? – Rex Sep 27 '17 at 18:45
  • It sounds like maybe the call to ProcessData should be called in an Ajax call rather than an Actionlink. – MUlferts Sep 27 '17 at 18:46
  • Possible duplicate of https://stackoverflow.com/questions/2856071/how-to-call-javascript-function-in-html-actionlink-in-asp-net-mvc – Rex Sep 27 '17 at 19:02

1 Answers1

0

I think the code below executes the someFunction function before the Controller/Action

@Html.ActionLink("linky", "action", "controller", new { onclick = "someFunction();"})

So if you want to control the flow you can use ajax, declare the button

<input type="button" id="btnAction" />

Then assign an action to your click event

$('#btnAction').click(someFunction);

And now implement your function using ajax

$.ajax({
            url: url/controller/action',
            type: 'GET',
            headers: headers,
            success: function (data) {
                //HERE YOUR CODE IN YOUR CONTROLLER WAS EXECUTED/FINISHED AND 
                //YOU CAN CALL YOUR JS FUNCTION

                yourSECONDfunction();
            }
        });
Victor Hugo Terceros
  • 2,969
  • 3
  • 18
  • 31