5

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?

7
  • And what exactly is the error? Commented Nov 28, 2017 at 13:03
  • @Jerodev...You read the post? View is Red, because there is no SendVerificationEmail view. Is this normal? Can this be resolved? Commented Nov 28, 2017 at 13:22
  • @dinotom can you please let me know from where you have open "Inspection options" dialog? Commented Nov 28, 2017 at 14:00
  • @programtreasures...from clicking on the red light bulb to the left of the code Commented Nov 28, 2017 at 14:22
  • Is this a ReSharper tool? It does look like a bug to me. Commented Nov 28, 2017 at 20:58

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.