gpt4 book ai didi

javascript - 如何在asp.net mvc中的html.actionlink中调用javascript确认对话框函数?

转载 作者:行者123 更新时间:2023-12-02 16:56:45 26 4
gpt4 key购买 nike

当用户单击删除按钮时,我想显示确认对话框菜单。

但是按钮不会触发我的脚本。触发 JavaScript 后,如果用户选择“确定”,脚本必须执行该操作。否则,如果用户单击“取消”,则不会发生任何情况。

这是 JavaScript 代码;

<script type="text/javascript">
$(document).ready(function () {
$(".confirmDialog").on("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: 170,
width: 350,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location = url;
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog('open');
return false;
});
});
</script>

这是MVC代码;

<div style="text-align: right; font-weight: bold; font-size: larger; color: red;">
<tr>
<td>@Html.ActionLink("Delete", "Your-Action", new { @class = "confirmDialog" })</td>
</tr>
</div>
<div id="dialog-confirm" style="display: none">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure ?
</p>
</div>

最佳答案

您使用的 Actionlink 重载需要将第三个参数作为对象路由而不是 htmlattributes

正确的操作链接如图所示:

@Html.ActionLink("Delete", "Your-Action", new{} ,new { @class = "confirmDialog" })

或者

@Html.ActionLink("Delete", "Your-Action", null ,new { @class = "confirmDialog" })

你的其余代码都很好..!!

关于javascript - 如何在asp.net mvc中的html.actionlink中调用javascript确认对话框函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26120008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com