-1

I new to asp.net mvc technology.

Here is my Controller:

public ActionResult SessionData()
    {
        return View();
    }

When button pressed on the view I need to implement ajax call and pass two strings to the controller above.

My question is how make ajax calls in asp.net mvc?Can I use HTML helper to generate ajax function?

Michael
  • 13,950
  • 57
  • 145
  • 288
  • Possible duplicate of [Proper way to use AJAX Post in jquery to pass model from strongly typed MVC3 view](http://stackoverflow.com/questions/5980389/proper-way-to-use-ajax-post-in-jquery-to-pass-model-from-strongly-typed-mvc3-vie) – Ilya Sulimanov Feb 04 '16 at 15:53

1 Answers1

0

You could use jQuery.ajax:

<script>
    $.ajax({
        url: '@Url.Action("MyAction")',
        type: 'POST',
        data: {
            arg1: 'value1',
            arg2: 'value2'
        },
        success: function(result) {
            alert('Successfully passed data to controller');
        }
    });
</script>

and the corresponding controller action may look like this:

public ActionResult MyAction(string arg1, string arg2)
{
    ... do something with those arguments and return a result

    return Json(new
    {
        someProperty = "some value"
    });
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928