我最近一直在学习MVC 3,我找到了两种从列表视图中删除记录的解决方案。但是我想要两者的组件,但是我对javascript缺乏了解,这使得这非常困难。
我有两个删除链接:
@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"
})
第一个使用以下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>
第二个链接使用此脚本函数进行确认:
<script>
function ConfirmDone() {
return confirm("Are you sure you want delete this item?");
}
</script>
现在这两个解决方案都运行正常,但我更喜欢第二个链接的编码,但我喜欢jquery-ui在第一个链接中生成的确认框。所以我想将它们混合在一起。
我认为我需要做的是当Ajax.ActionLink
调用ConfirmDone()
然后我需要像第一个链接一样显示jquery对话框。但是我不确定如何生成它并允许此对话框返回true或false,具体取决于按下的按钮。
非常感谢任何帮助。
非常感谢。
答案 0 :(得分:0)
经过几个小时的尝试后,我想出了一个解决方案:
我的链接更改为:
@Ajax.ActionLink("Delete", "Delete", "StruContractUser",
new { id = item.UserID },
new AjaxOptions {
HttpMethod = "Delete",
OnBegin = "JSONDeleteFile_OnBegin",
OnComplete = "notify"
},
new { @class = "delete-link" })
使用OnBegin
选项调用此函数:
<script type="text/javascript">
function JSONDeleteFile_OnBegin(context) {
return false;
}
</script>