我对 MVC 和 Javascript 还很陌生;我正在尝试使删除操作起作用;我正在使用带有 Javascript 函数的 ActionLink 进行确认。 JAvascript 确认不起作用,即使按取消也会触发删除操作;另外,我似乎无法使用 [HttpDelete] 动词来执行操作:我需要将两个参数传递给删除操作,但是在它搜索的操作链接上应用 @Html.HttpMethodOverride(Http.Delete) 后 对于只有一个参数的 URL:id。
这是我的代码:操作链接
@Html.HttpMethodOverride(HttpVerbs.Delete)
@Html.ActionLink(
"Delete",
"Delete",
new {id=notification.Id, typeId=notification.TypeId},
new {onclick="confirmDeleteAction()"})
function confirmDeleteAction() {
return confirm('Are you sure you want to delete the notification ?');
}
删除操作:
[HttpDelete]
public ActionResult Delete(int id, int typeId)
{
Service.DeleteNotification(id, typeId);
NewIndexViewModel model = Service.GetNewIndexViewModel();
return View("Index", model);
}
最佳答案
试试这个
@Html.ActionLink(
"Delete",
"Delete",
new {id=notification.Id, typeId=notification.TypeId},
new {onclick="return confirmDeleteAction();"})
关于javascript - MVC : Javascript confirm for delete action not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17875501/