MVC 4 操作 link 弹出框确认删除?
MVC 4 action link popup box confirmation for delete?
单击操作link执行删除时弹出确认窗口的最佳方式是什么?目前当我按下删除操作 link 时,它会直接删除。无论如何执行弹出确认框删除?
谢谢!
我的看法:
<td>
@Html.ActionLink("Delete", "SURV_Question_Delete", "SURV_Question", new { Question_ID = Model[i].Question_ID }, null)
</td>
我的控制器:
public ActionResult SURV_Question_Delete(int Question_ID)
{
var query = from r in db.SURV_Question_Ext_Model.ToList()
where r.Qext_Question_ID == Question_ID
select r;
foreach(var item in query)
{
db.SURV_Question_Ext_Model.Remove(item);
db.SaveChanges();
}
return RedirectToAction("SURV_Main_Edit", "SURV_Main", new { id = surveyId });
}
这样试试,在link上在线添加调用javascript函数确认。
@Html.ActionLink("Delete", "SURV_Question_Delete", "SURV_Question",
new { Question_ID = Model[i].Question_ID, onclick = "return
DeleteConfirm()" }, null)
function DeleteConfirm()
{
if (confirm("Are you sure want to delete record"))
return true;
else
return false;
}
你也可以试试这个
@Html.ActionLink("Delete", "SURV_Question_Delete", "SURV_Question",
new { Question_ID = Model[i].Question_ID, onclick="return confirm('Are you sure?');"},null);
首先,您的删除操作应该是 POST,而不是 GET。您的修改数据,不希望将此添加到浏览器历史记录中,或允许在地址栏中输入 url(该项目可能已被删除)
将您的 html 更改为
@using (Html.BeginForm("SURV_Question_Delete", "SURV_Question", new { Question_ID = Model[i].Question_ID }))
{
@Html.AntiForgeryToken()
<input type="submit" value="delete" />
}
并使用 [HttpPost]
和 [ValidateAntiForgeryToken]
属性修饰方法。
然后添加脚本
$('form').submit(function() {
// Modify the following to use you jquery-ui-dialog, but for testing purposes
if (!confirm("Are you sure want to delete record") {
return false; // cancel the submit if the user clicked the Cancel button
}
});
You also can do the following, which will show the confirm box with
the value you want to delete, which is more perfect in case of
deleting.
@Html.ActionLink("Delete Subject", "DeleteSubject", "Subjects", new { SubjectId = _item.SubjectMsId },
new { onClick = "return confirm('Are you sure, you want to Delete the Subject : "+
@_item.SubjectName+" ?')" })
单击操作link执行删除时弹出确认窗口的最佳方式是什么?目前当我按下删除操作 link 时,它会直接删除。无论如何执行弹出确认框删除? 谢谢!
我的看法:
<td>
@Html.ActionLink("Delete", "SURV_Question_Delete", "SURV_Question", new { Question_ID = Model[i].Question_ID }, null)
</td>
我的控制器:
public ActionResult SURV_Question_Delete(int Question_ID)
{
var query = from r in db.SURV_Question_Ext_Model.ToList()
where r.Qext_Question_ID == Question_ID
select r;
foreach(var item in query)
{
db.SURV_Question_Ext_Model.Remove(item);
db.SaveChanges();
}
return RedirectToAction("SURV_Main_Edit", "SURV_Main", new { id = surveyId });
}
这样试试,在link上在线添加调用javascript函数确认。
@Html.ActionLink("Delete", "SURV_Question_Delete", "SURV_Question",
new { Question_ID = Model[i].Question_ID, onclick = "return
DeleteConfirm()" }, null)
function DeleteConfirm()
{
if (confirm("Are you sure want to delete record"))
return true;
else
return false;
}
你也可以试试这个
@Html.ActionLink("Delete", "SURV_Question_Delete", "SURV_Question",
new { Question_ID = Model[i].Question_ID, onclick="return confirm('Are you sure?');"},null);
首先,您的删除操作应该是 POST,而不是 GET。您的修改数据,不希望将此添加到浏览器历史记录中,或允许在地址栏中输入 url(该项目可能已被删除)
将您的 html 更改为
@using (Html.BeginForm("SURV_Question_Delete", "SURV_Question", new { Question_ID = Model[i].Question_ID }))
{
@Html.AntiForgeryToken()
<input type="submit" value="delete" />
}
并使用 [HttpPost]
和 [ValidateAntiForgeryToken]
属性修饰方法。
然后添加脚本
$('form').submit(function() {
// Modify the following to use you jquery-ui-dialog, but for testing purposes
if (!confirm("Are you sure want to delete record") {
return false; // cancel the submit if the user clicked the Cancel button
}
});
You also can do the following, which will show the confirm box with the value you want to delete, which is more perfect in case of deleting.
@Html.ActionLink("Delete Subject", "DeleteSubject", "Subjects", new { SubjectId = _item.SubjectMsId },
new { onClick = "return confirm('Are you sure, you want to Delete the Subject : "+
@_item.SubjectName+" ?')" })