jQueryAjax调用和Html.antiForgeryToken()
ASP.NETMVC框架中的AntiForgeryToken-Html.AntiForgeryToken和ValidateAntiForgeryToken属性
[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) {
// ....
}
});});萧十郎
烙印99
相关分类