我对 MVC 和 Javascript 很陌生;我正在尝试进行删除操作;我正在使用带有 Javascript 函数的 ActionLink 进行确认。JAvascript 确认不起作用,即使我按下取消也会触发删除操作;此外,我似乎无法对动作使用 [HttpDelete] 动词:我需要将两个参数传递给 Delete 动作,但在动作链接上应用 @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);
}