You do not call actionlink with jQuery. You can send an AJAX request for the controller action that this link points to. If this is what you want, here's how to achieve this:
$(function() {
$('#paycheck').click(function () {
if ($('#terms').is(':checked')) {
$.ajax({
url: this.href,
type: 'GET',
data: { foo: 'bar' },
success: function(result) {
}
});
} else {
alert('Please agree to the terms and conditions.');
}
return false;
});
});
Also make sure that you provide the correct identifier ( paycheck) to reference the action when creating it
<%= Html.ActionLink("Pay", "Index", "News", null, new { id = "paycheck" }) %>
But if it is only a matter of checking whether the user accepted the conditions and then performed the standard redirect to the controller action without any AJAX, just do this:
$(function() {
$('#paycheck').click(function () {
if ($('#terms').is(':checked')) {
return true;
}
alert('Please agree to the terms and conditions.');
return false;
});
});
source
share