如何在 mvc 中的 ajax 操作 link 中包含 AntiForgeryToken?

how to include AntiForgeryToken in an ajax action link in mvc?

我有以下代码:

@Ajax.ActionLink("Delete", "Delete", 
new { id = item.ID, RequestVerificationToken=*What comes here?*}, 
new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "formsIndex" })

我想在客户端不使用 javascript 将验证令牌添加到 link,这似乎是一个多余的依赖,因为我已经在服务器中拥有该值。有正确的方法吗?

来自MSDN documentation(我的重点)

HtmlHelper.AntiForgeryToken Method

Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.

您需要一个表单元素来生成防伪令牌。

@Ajax.BeginForm("Delete", new { id = item.ID }, new AjaxOptions { UpdateTargetId = "formsIndex" }))
{
  @Html.AntiForgeryToken()
  <input type="submit" value="Delete" /> // style to look like a link if that's what you want
}