[英]MVC3 Ajax link confirmation dialog using jquery-ui dialog box
I have been learning MVC 3 recently and I have found two solutions to deleting records from my list view. 我最近在学习MVC 3,并且找到了两种从列表视图中删除记录的解决方案。 However I would like components of both of them, but my lack of knowledge in javascript is making this very difficult.
但是我想要它们的组件,但是我对javascript的了解不足使这一点变得非常困难。
I have these two links for deleting: 我有两个要删除的链接:
@Html.ActionLink("Delete", "Delete",
new { id = item.ID }, new { @class = "delete-link" }) |
@Ajax.ActionLink("Delete Ajax", "Delete", "MyController",
new {id = item.ID},
new AjaxOptions {
HttpMethod = "POST",
OnBegin = "return ConfirmDone()",
OnSuccess = "deleteConfirmation"
})
The first one uses the following javascript to delete the record: 第一个使用以下javascript删除记录:
<script>
$(function () {
var deleteLinkObj;
// delete Link
$('.delete-link').click(function () {
deleteLinkObj = $(this);
$('#delete-dialog').dialog('open');
return false;
});
//definition of the delete dialog.
$('#delete-dialog').dialog({
autoOpen: false, width: 400, resizable: false, modal: true,
buttons: {
"Continue": function () {
$.post(deleteLinkObj[0].href, function (data)
{
var rowId = "#myTableItem-id-" + data.id;
$('.myTable').find(rowId).hide('slow');
});
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
</script>
The second link uses this script function for confirmation: 第二个链接使用此脚本功能进行确认:
<script>
function ConfirmDone() {
return confirm("Are you sure you want delete this item?");
}
</script>
Now both of these solutions work fine, however I prefer the coding of the second link, but I like the confirmation box that jquery-ui produces in the first link. 现在这两个解决方案都可以正常工作,但是我更喜欢第二个链接的编码,但是我喜欢jquery-ui在第一个链接中生成的确认框。 So I would like to blend them together.
所以我想将它们融合在一起。
What I think I need to do is when the Ajax.ActionLink
calles the ConfirmDone()
then I need to show a jquery dialog as I do with the first link. 我想我需要做的是,当
Ajax.ActionLink
调用ConfirmDone()
我需要像第一个链接一样显示一个jquery对话框。 However I am unsure how to produce this and allow this dialog to return a true or false depending on the button that is pressed. 但是我不确定如何产生此结果,并允许此对话框根据所按下的按钮返回true或false。
Any help would be much appreciated. 任何帮助将非常感激。
Thanks very much. 非常感谢。
After a few hours of trying things out I have came up with a solution: 经过几个小时的尝试,我想出了一个解决方案:
My link changed to this: 我的链接更改为:
@Ajax.ActionLink("Delete", "Delete", "StruContractUser",
new { id = item.UserID },
new AjaxOptions {
HttpMethod = "Delete",
OnBegin = "JSONDeleteFile_OnBegin",
OnComplete = "notify"
},
new { @class = "delete-link" })
Which calls this function with the OnBegin
option: 使用
OnBegin
选项调用此函数:
<script type="text/javascript">
function JSONDeleteFile_OnBegin(context) {
return false;
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.