0

Is there an easy way of replacing the generated output of Helper function Ajax.ActionLink to use Jquery instead of MS ?

Or must i do all the job in a custom Extension? Someone must have done this

EDIT:

I think i'm looking at replacing the MicrosoftMVCAjax.js with something done with JQuery. Something called JQueryMVCAjax perhaps...

1 Answer 1

2

Start by replacing Ajax.ActionLink with Html.ActionLink in your view and give it an unique id so that you could attach handlers to it in javascript:

<%: Html.ActionLink("link text", "action", "controller", null, 
    new { id = "mylink" }) %>

And then attach a click handler in a separate js file:

$(function() {
    $('#mylink').click(function() {
        // send ajax request
        $.get(this.href, function(result) {
            // The ajax request succeeded => do something with the results
            alert(result);
        });
        // make sure you cancel the default redirect action
        return false;
    });
});

If you just want to replace the contents of some div with the result of the AJAX request you could use the .load() function:

$(function() {
    $('#mylink').click(function() {
        $('#resultDiv').load(this.href);
        return false;
    });
});
Sign up to request clarification or add additional context in comments.

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.