Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Asp.Net Core web template comes with error

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);

VS Inspection of red squiggly under View

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?

like image 500
dinotom Avatar asked Oct 29 '22 22:10

dinotom


1 Answers

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.

like image 146
dinotom Avatar answered Nov 15 '22 04:11

dinotom