【发布时间】:2013-07-26 07:33:23
【问题描述】:
我对 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);
}
【问题讨论】:
-
要将两个参数传递给删除方法,您必须在 Route.config 文件中添加一个条目
-
如果你想使用动词,请访问blog