Я хочу подтвердить.
Контроллер не хочет получать данные.
Eat удалите ValidateAntiForgeryToken, затем примете ноль.
В представлении Html.AntiForgeryToken ().

Вот мой код:
getDataTable = async (e) => {
try {
const { Login, Password } = this.state;
var data = new FormData();
data.append("Login", Login);
data.append("Password", Password);
data.append("__RequestVerificationToken", this.props.__RequestVerificationToken);
const response = await fetch(urlControlActionAccountLogin, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "cors", // no-cors, cors, *same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Accept": "application/json, application/xml, text/plain, text/html, *.*",
//"Content-Type": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
redirect: "follow", // manual, *follow, error
referrer: "no-referrer", // no-referrer, *client
body: data, // body data type must match "Content-Type" header
});
const json = await response.json();
//this.setState({ textarea: json.description });
this.setState({
isLoaded: true,
});
console.log(json);
} catch (error) {
this.setState({
isLoaded: true,
error
});
console.error(error);
}
};
C # Контроллер ASP.net core 2.2
JS должен отправить данные пароля для входа, и контроллер примет
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login([FromForm]string _model) //[FromBody]LoginModel model
{
var model = JsonConvert.DeserializeObject<LoginModel>(_model); //[FromForm]string _model
//var model = _model.ToObject<LoginModel>(); //[FromForm]JObject _model
var a = db.GetUserContext();
if (ModelState.IsValid)
{
User user = await db.Users.FirstOrDefaultAsync(u => u.Login == model.Login && u.Password == model.Password);
if (user != null)
{
await Authenticate(model.Login); // аутентификация
return Json(new
{
user
});
}
ModelState.AddModelError("", "Некорректные логин и(или) пароль");
}
return View(model);
}