开发者

Replace Ajax.ActionLink output to use Jquery

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...


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;
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜