title: ASP MVC 4 Ajax.ActionLink for delete using AntiForgeryToken
body: <p>I have a number of index pages where the row has an actionlink like so</p>
  
  <pre><code>@Ajax.ActionLink("Delete", "Delete", "AdverseEvent", new { id = Model.AdverseEventId }, new AjaxOptions { HttpMethod = "Post",OnSuccess = "rowDeleted", LoadingElementId="ajaxRequest_processing", Confirm = String.Format("Are you sure you want to delete adverse event for participant {0} at {1} ?", Model.ParticipantId, Model.EventTime) }, new { @class = "deleteAction" })
  </code></pre>
  
  <p>An actionlink is a great way to use progressive enhancement, because of course there is also a delete action, with get and post methods to perform the delete for those with javascript disabled.</p>
  
  <p>I need to add an AntiForgeryToken. For an Ajax.BeginForm helper, <a href="http://jonwhite.me/2012/09/16/how-to-use-antiforgery-tokens-with-ajax-in-asp-net-mvc/" rel="nofollow">Jon White's</a> code works beautifully:</p>
  
  <pre><code>$.ajaxPrefilter(function (options, localOptions, jqXHR) {
      var type = options.type.toLowerCase();
      if (type === 'post') {
          var token = GetAntiForgeryToken();
          jqXHR.setRequestHeader(token.name, token.value);
      }
  });
  </code></pre>
  
  <p>When this gets executed within an actionlink, I assume because the index table is not wrapped in a form, I get the error message:</p>
  
  <pre><code>The required anti-forgery form field "__RequestVerificationToken" is not present
  </code></pre>
  
  <p>So i could wrap the whole table in a form posting back to the delete action, but this is then not very neat if I want to use other ajax.actionlinks to different actions within the table. I could wrap each actionlink in its own form, each with its own antiforgery token, but this is a significant amount of extra markup, and will leave dozens of elements on the page with identical values and name. The other option would be to use the ActionLink OnBegin method to wrap the button in a form, but the unobtrusive ajax library does not seem to pass any reference to the element causing the ajax get/post (foolishly in my opinion - you can upvote this issue on <a href="https://aspnet.codeplex.com/workitem/10335" rel="nofollow">codeplex</a>).</p>
  
  <p>Any thoughts on a neat solution? Thank you.</p>