【发布时间】:2021-11-04 06:49:47
【问题描述】:
在我的 MVC 项目中,我通过 AngularJs 调用 method。我需要将AntiForgeryToken 发送到method。
在视图中
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
...
}
在 MVC 中controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Model model)
{
...
}
在 AngularJs 中 controller
this.data.Name= $('#txtNm').val();
this.data.Id = $('#Id').val();
var token = angular.element("input[name='__RequestVerificationToken']").val();
$http({
method: "POST",
url: "/Students/Create",
dataType: 'json',
data: this.data,
headers: {
'__RequestVerificationToken': token
}
}).then(function (response) {
//success
}, function (response) {
//error
});
但是,它不起作用。
【问题讨论】:
标签: angularjs asp.net-mvc