0

I am new to both MVC and JQuery, but this should not really be that difficult. When I call the function, nothing happens. I put an alert box in the function, and I can see that the function is called.

I found this, but it did not help me: Calling ASP.NET MVC Action Methods from JavaScript

This is my script:

<script type="text/javascript">
    function oKButtonPressed(){    
        jQuery.ajax({
            type: "POST",
            url: "@Url.Action("MessageToPatient", "StartScreen")"
        });
    };
</script>

MessageToPatient is the name of the action method. StartScreen is the name of the controller.

Can you see something obvious I'm missing? Otherwise, it might be something with my MVC code.

14
  • Put a breakpoint inside your controller action to see if the action actually gets called. Commented May 24, 2015 at 14:59
  • By the way, you're not passing any data with your ajax post. Commented May 24, 2015 at 15:02
  • I put a breakpoint in it, and the action method is called. Commented May 24, 2015 at 15:05
  • Hmm, I mean all I want to do is call the action method, without any data passed. Commented May 24, 2015 at 15:05
  • Then, why does it have to be a post call? Commented May 24, 2015 at 15:09

1 Answer 1

2

You are Getting/posting to an action using jQuery.Ajax.

You can return data to this jQuery, but an MVC view will not be rendered as if it was just a normal request. You have to process the returned data in some way.

See this for example: http://www.itorian.com/2013/02/jquery-ajax-get-and-post-calls-to.html?m=1

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, thanks. Well if you were to just call an action method that renders a view with a button click, how would you do it?
Try googling a beginner's MVC tutorial, it'd be quicker than asking q's on here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.