1

I am successfully using @Ajax.ActionLink to refresh data on a portion of my page, but I would like to do the same from Javascript. How can I simulate the effects of clicking that ActionLink in js?

Thanks!

@Ajax.ActionLink("ClickMe", "List", "Organizations", New AjaxOptions With {.UpdateTargetId = "dashboardDetails"})
1
  • Very old question, but in need of an update. As you are using Ajax.ActionLink, you can simply trigger that link from JQuery. Example added below. Commented Jan 23, 2014 at 17:27

3 Answers 3

2

You need to look at using the $.get() and .$post() jQuery functions. So basically, you can perform a call to a controller action, from Javascript, using either of these functions (depending on whether your getting or posting data).

An example can be found here.

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

1 Comment

Thank you Jason, $.get() appears to handle what I need to do.
2

Behind the scenes Unobtrusive,JQuery simply matches on the ajax links with a[data-ajax=true] and runs this code:

$(document).on("click", "a[data-ajax=true]", function (evt) {
    evt.preventDefault();
    asyncRequest(this, {
        url: this.href,
        type: "GET",
        data: []
    });
});

asyncRequest simply runs an $.ajax call with all the options assembled for it.

You can get the same effect by simply sending a click to your link. Assuming you give your link an id with the optional HtmlAttributes like this:

@Ajax.ActionLink("ClickMe", "List", "Organizations", New AjaxOptions With {.UpdateTargetId = "dashboardDetails"}, new { id = "myajaxLink" })

you can simply trigger it with:

$('#myajaxLink').click();

Comments

0

JQuery has extensive support for ajax calls.

http://api.jquery.com/jQuery.ajax/

also check this blog out

Using jQuery ajax to load a partial view in ASP.NET MVC 2 and then retrieve the input on the server again

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.