views:

14

answers:

1

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  A: 

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;
    });
});
Darin Dimitrov