在表单中添加一个名为“__RequestVerificationToken”的隐藏字段。这样可以确保提交的请求具有适当的防伪标记并在控制器中确保绑定值正确。
示例代码:
在表单中添加隐藏字段:
在控制器中确保绑定值正确:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult MyOtherAction(MyModel model)
{
if (ModelState.IsValid)
{
// do something with your model
return RedirectToAction(nameof(MyOtherActionSuccess));
}
return View(model);
}