Вы не вызываете actionlink , используя jQuery.Вы можете отправить AJAX-запрос к действию контроллера, на которое указывает эта ссылка.Если это то, что вы хотите, вот как это сделать:
$(function() {
$('#paycheck').click(function () {
if ($('#terms').is(':checked')) {
// Send an AJAX request to the controller action this link is pointing to
$.ajax({
url: this.href,
type: 'GET',
// you can send some additional data along with the request
data: { foo: 'bar' },
success: function(result) {
// TODO: process the results returned by the controller
}
});
} else {
alert('Please agree to the terms and conditions.');
}
return false;
});
});
Также убедитесь, что вы указали правильный идентификатор (paycheck
) для своей ссылки действия при генерации
<%= Html.ActionLink("Pay", "Index", "News", null, new { id = "paycheck" }) %>
Но если это только вопрос проверки, принял ли пользователь положения и условия, а затем выполнить стандартное перенаправление на действие контроллера без AJAX, просто сделайте это:
$(function() {
$('#paycheck').click(function () {
if ($('#terms').is(':checked')) {
// by returning true you are letting the browser redirect to the link
return true;
}
alert('Please agree to the terms and conditions.');
// By returning false you stay on the same page and let the user
// agree with the terms and conditions
return false;
});
});