I am dealing with this ASP.NET MVC problem of that using ValidateAntiForgeryToken with AJAX breaks the AJAX call (Using ValidateAntiForgeryToken with Ajax.ActionLink). The only solution (as stated in that topic) requires jQuery.
How do i do the eqvivalent of the following with jQuery's .post method?
@Ajax.ActionLink("Perform HTTPPost", "PostTest", new AjaxOptions{ HttpMethod="POST"})
Here is the Controller:
// [ValidateAntiForgeryToken]
public class MoreInfoController : Controller
{
[HttpPost]
public ActionResult PostTest()
{
return View();
}
}
Here is it's Index VIEW with both Javascript and HTML:
$(document).ready(function () {
$('#linkToPost').click(PostForm);
});
function PostForm() {
$.post("/PostTest", $('#testForm').serialize(), function(data) {
});
return false;
}
@Html.AntiForgeryToken()
And here is the Route:
routes.MapRoute("PostTest1",
"PostTest",
new {controller = "MoreInfo", action = "PostTest"}
);