【问题标题】:MVC jquery dialog not working properlyMVC jquery 对话框无法正常工作
【发布时间】:2014-12-16 10:00:38
【问题描述】:

当我单击删除按钮时,弹出对话框显示然后消失。它不会留下来

这里是代码:

.cshtml:

@Html.ActionLink("Delete", "DeleteOrder", "Order", new { id = item.OrderID }, new { @class = "btn btn-primary btn-delete"} );


<div id="dialog-confirm" title="Confirmation Dialog" style="display:none">Delete this Order? Confirm </div>

 <script>
  $(document).ready(function () {

        $(".btn-delete").click(function () {
            var result;                

            $("#dialog-confirm").dialog({
                resizable: false,
                height: 140,
                modal: true,
                buttons: {
                    "Yes": function () {
                        $(this).dialog("close"); 
                    },
                    "No": function () {
                        $(this).dialog("close");
                        return false;
                    }
                }
            });                 

        });
});
</script>

【问题讨论】:

  • 只是一个想法,不用设置值和传递,当用户点击yes时直接返回true。这适用于你的场景吗?

标签: javascript jquery model-view-controller


【解决方案1】:

处理您的锚点单击并打开对话框,如果是,则将浏览器 url 设置为锚点 href 属性

$(".btn-delete").click(function(e) {
 var ahref = $(this)
  $("#dialog-confirm").dialog({
    resizable: false,
    height: 140,
    modal: true,
    buttons: {
      "Yes": function() {
        $(this).dialog("close");
       
        window.location = $(ahref).prop("href");
      },
      "No": function() {
        $(this).dialog("close");
      }
    }
  });

    e.preventDefault();
});
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

<a href="http://example.com" class="btn-delete">delete item</a>
<div id="dialog-confirm"></div>

【讨论】:

  • 当我点击“是”时,它会提交,但会得到 Requested URL: /Mvc5/undefined
猜你喜欢
  • 1970-01-01
  • 2014-10-18
  • 2014-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多