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