I found many examples demonstrating how to add an AntiForgeryToken call to Ajax for the POST send method. My need, as the name suggests, is to submit the NOT form via an Ajax call. Instead, I just use the jQuery submit() function.
What I have in the razor view file is as follows (Note: I use the html string literal because this particular DOM must be dynamically bound to a single element at a later point):
var html = "<form id='exportPdfForm' action='" + exportUrl + "' method='post'>" + "<input type='hidden' id='exportContent'>" + "<input type='hidden' id='__RequestVerificationToken' value='@Html.AntiForgeryToken()'>" + "</form>";
And obviously, I am using the following jQuery to submit this form:
$("#exportPdfForm").submit();
Also, using the DOM Explorer, I see that the AntiForgeryToken value is AntiForgeryToken correctly: 
However, when I actually submit the form, I still encounter the error The required anti-forgery form field "__RequestVerificationToken" is not present . I checked several other Q&A, but I can not find anything that could shed light on my problem.
Did I miss something obvious or did something wrong?
EDIT (solution)
Assigning the __RequestVerificationToken attribute to the name attribute will be fixed:
<input type='hidden' name='__RequestVerificationToken' value='...'>
source share