By default, the Asp.Net Core web template has an error

Can someone explain why the default Asp.Net template template with individual user identification contains an error in the control manager?

 [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 line of code

return View(model);

VS Checking red squiggly under View

The view is Red because there is no SendVerificationEmail view. This is normal? Can this be solved?

I could specify a view for routing as

 if (!ModelState.IsValid)
 {
     return View(nameof(Index),model);
 }

but is it really what the Asp.Net team intended it from here?

+4
source share
1 answer

It seems, and I agree with several people whom I showed that this could be a mistake. Not sure how to report this, but given the model - IndexViewModel, I fixed it by routing the result of returning to the index view.

 if (!ModelState.IsValid)
 {
     return View(nameof(Index),model);
 }

, Asp.Net , (kludge) . , , .

+1

Source: https://habr.com/ru/post/1689960/


All Articles