我如何停止重定向ActionLink的,而是弹出和使用JavaScript重定向? [英] How do I stop an Actionlink redirect and instead popup and redirect using javascript?

查看:319
本文介绍了我如何停止重定向ActionLink的,而是弹出和使用JavaScript重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是脚本我有什么现在 -

This is script what I have currently -

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

下面是有没有为每条记录的链接,我们可以删除每个系统当我们点击了删除按钮 -

Here is the link which is there for each record and we can delete each system when we click on its delete button -

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

现在这里是ActionLink的重定向不管发生什么问题,我需要阻止它。我的意思是说,用户presses上确认的ActionLink仍然执行并进入RemoveSystem行动,在这里我希望它只是停留在page.I取消想到使用HTML超链接,但我不知道我应该怎么通过ID值,以在此情况下的JavaScript。任何人都可以请帮我吗?

Now here is the problem the actionlink redirects no matter what happens and I need to stop it. I mean say the user presses cancel on the confirm the actionlink still executes and goes to RemoveSystem Action, where I want it to just stay on the page.I thought of using a HTML hyperlink but I dont know how I should pass id the value to the javascript in that case. Can anyone please help me out ?

推荐答案

您需要prevent的的默认的这样的链接的动作:

You need to prevent the default action of the link like this:

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

或者这样:

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

目前,该链接是这样做的功能,但的做什么,没有的JavaScript可言,这是去确实在的href 它有...这是你需要prevent的发生的行为。

Currently, the link is doing this function but also doing what it does with no JavaScript at all, which is to go to the href it has...that's the behavior you need to prevent from happening.

这篇关于我如何停止重定向ActionLink的,而是弹出和使用JavaScript重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆