✅ Token present on Get but missing on Post using Identity

Pasted images to show autos with breakpoints. Code present on Get but missing on Post. I'm not sure what could cause it to drop in between?
public IActionResult ResetPassword(string code =null)
{
return code == null ? View("Error") : View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> ResetPassword(ResetPasswordViewModel resetPasswordViewModel)
{
if(ModelState.IsValid)
{
var user = await _userManager.FindByEmailAsync(resetPasswordViewModel.Email);
if(user == null)
{
ModelState.AddModelError("Email", "User not found");
return View();
}
var result = await _userManager.ResetPasswordAsync(user, resetPasswordViewModel.Code, resetPasswordViewModel.Password);
if(result.Succeeded)
{
return RedirectToAction("ResetPasswordConfirmation");
}
}
return View(resetPasswordViewModel);
}
public IActionResult ResetPassword(string code =null)
{
return code == null ? View("Error") : View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> ResetPassword(ResetPasswordViewModel resetPasswordViewModel)
{
if(ModelState.IsValid)
{
var user = await _userManager.FindByEmailAsync(resetPasswordViewModel.Email);
if(user == null)
{
ModelState.AddModelError("Email", "User not found");
return View();
}
var result = await _userManager.ResetPasswordAsync(user, resetPasswordViewModel.Code, resetPasswordViewModel.Password);
if(result.Succeeded)
{
return RedirectToAction("ResetPasswordConfirmation");
}
}
return View(resetPasswordViewModel);
}
3 Replies
Saber
Saber2y ago
The code needs to be in a hidden input in the form so it gets posted
BigggMoustache
It won't pass to the viewmodel unless there's a form in the view to put it in the model? Apparently I've been confused how the get, post, and view interact. Thank you very much for clearing this up for me.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts