Can anyone explain why the default Asp.Net Web Application template, with Individual user identification, comes with an error in the Manage Controller?
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> SendVerificationEmail(IndexViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
var email = user.Email;
await _emailSender.SendEmailConfirmationAsync(email, callbackUrl);
StatusMessage = "Verification email sent. Please check your email.";
return RedirectToAction(nameof(Index));
}
In this code line;
return View(model);
View is Red, because there is no SendVerificationEmail view. Is this normal? Can this be resolved?
I could specify a view to route to like
if (!ModelState.IsValid)
{
return View(nameof(Index),model);
}
but is that really where the Asp.Net team intended this to go from here?
It appears, and is agreed to by a few people I've shown this to, that it may be a bug. Not sure how to report that but given the model is an IndexViewModel, I fixed it by routing the return result to the index view.
if (!ModelState.IsValid)
{
return View(nameof(Index),model);
}
Not sure if that is where the Asp.Net default application team meant for this to re-route but that's the fix(kludge) I'm going with. Any better solutions, please comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With