jQueryAjax调用和Html.antiForgeryToken()
[ValidateAntiForgeryToken]
[HttpPost][ValidateAntiForgeryToken]public ActionResult SomeAction( SomeModel model ) {}
<%= Html.AntiForgeryToken() %>
<div style="text-align:right; padding: 8px;"> <%= Html.AntiForgeryToken() %> <input type="submit" id="btnSave" value="Save" /></div>
$("a.markAsDone").click(function (event) { event.preventDefault(); $.ajax({ type: "post", dataType: "html", url: $(this).attr("rel"), data: {}, success: function (response) { // .... } });});
<%= Html.AntiForgeryToken() %>
编辑:
$("a.markAsDone").click(function (event) { event.preventDefault(); $.ajax({ type: "post", dataType: "html", url: $(this).attr("rel"), data: { AddAntiForgeryToken({}), id: parseInt($(this).attr("title")) }, success: function (response) { // .... } });});