如何停止Actionlink重定向,而是使用javascript弹出和重定向?

Vis*_*hal 1 javascript popup actionlink asp.net-mvc-2

这是我目前的脚本 -

<script type="text/javascript">
        $(document).ready(function () {
            $('.RemoveSystem').click(function () {
                var href = $(this).attr('href');
                var answer = confirm("Are you sure you want to delete this system?");
                alert(answer);
                if (answer) 
                    window.location = href;
            });
        });
    </script> 
Run Code Online (Sandbox Code Playgroud)

这是每个记录的链接,我们可以在点击删除按钮时删除每个系统 -

 <%= Html.ActionLink("Delete", "RemoveSystem", new { SysNum = item.Id}, new { @class = "RemoveSystem" })%>
Run Code Online (Sandbox Code Playgroud)

现在这里是actionlink重定向的问题,无论发生什么,我需要阻止它.我的意思是说用户按下取消确认动作链接仍然执行并转到RemoveSystem动作,我希望它只留在页面上.我想使用HTML超链接但我不知道我应该如何将id传递给id那种情况下的javascript.有人可以帮帮我吗?

Nic*_*ver 6

您需要阻止链接的默认操作,如下所示:

$('.RemoveSystem').click(function () {
  if (confirm("Are you sure you want to delete this system?")) 
    window.location = $(this).attr('href');
  return false;
});
Run Code Online (Sandbox Code Playgroud)

或这个:

$('.RemoveSystem').click(function (e) {
  if (confirm("Are you sure you want to delete this system?")) 
    window.location = $(this).attr('href');
  e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

目前,该链接正在执行此功能,但也完成它没有使用任何JavaScript的功能,这就是href它具有...这是您需要防止发生的行为.