我有一个包含数据表的mvc视图。我想在其中包含一个“删除”按钮,以便用户可以删除记录。我无法生成正确的链接以转到我的删除操作。为了删除我需要表中的两个值,而不仅仅是一个id。
<td>
@Ajax.ActionLink("Delete",
"DeleteWorkItem",
"Project/Work",
new { hId = @w.ProjectId, workId = @w.WorkId},
new AjaxOptions()
{
AllowCache = false,
HttpMethod = "DELETE",
Confirm = "Are you sure you want to delete this record?"
})
</td>
是我到目前为止,但是当点击链接时,它会创建对URL的Get请求,并在查询字符串中附加这两个参数。如何在url而不是查询字符串中获取这些参数值。此外,我想调用http删除方法,但无论我放在那个选项值,我得到一个得到 我的WorkController
[HttpDelete]
public ActionResult DeleteWorkItem(int hId, int workId)
{
this.brWorkManager.Delete(forhealthId, workId);
return RedirectToAction("Details");
}
我的路线:
routes.MapRoute(
"WorkItemDelete",
"FHProject/Work/DeleteWorkItem",
new { controller = "Work", action = "DeleteWorkItem" },
new { httpMethod = new HttpMethodConstraint("DELETE") }
);