【发布时间】:2017-07-02 14:43:18
【问题描述】:
我正在尝试显示一个自定义警报框以确保用户想要删除一个项目。删除该项目后,会打开一个新警报框并显示“该项目已删除”,然后用户必须单击“确定”按钮。
我的问题是,删除该项目后,该页面被重定向到另一个页面,而无需单击“确定”按钮。我怎样才能安排代码来实现我的观点。
控制器;
public ActionResult Delete(int id)
{
Category category = db.Categories.Find(id);
db.Categories.Remove(category);
db.SaveChanges();
return RedirectToAction("Index");
}
删除按钮;
<button type="button" class="btn bg-red waves-effect" onclick="Delete();">Delete</button>
警报脚本;
<script>
function Delete()
{
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function () {
location.href = '@Url.Action("Delete", "Categories", new { id = Model.Id })',
swal({
title: "Deleted!",
text: "Your imaginary file has been deleted.",
type: "success"
})
});
}
</script>
【问题讨论】:
标签: javascript jquery asp.net asp.net-mvc razor