在Controller的方法中加入[ValidateAntiForgeryToken]属性
代码示例:
[HttpPost] [ValidateAntiForgeryToken] // 加入验证属性 public IActionResult Create(Employee employee) { if (ModelState.IsValid) { _employeeRepository.AddEmployee(employee); return RedirectToAction("Index"); }
return View(employee);
}