谁能解释为什么带有个人用户标识的默认 Asp.Net Web 应用程序模板在管理 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));
}
在此代码行中;
return View(model);
View 为红色,因为没有 SendVerificationEmail View 。这是正常的吗?这个能解决吗?
我可以指定一个 View 来路由到喜欢的地方
if (!ModelState.IsValid)
{
return View(nameof(Index),model);
}
但这真的是 Asp.Net 团队打算从这里开始的地方吗?
最佳答案
看起来,并且我已经向一些人展示过,这可能是一个错误。 不确定如何报告,但鉴于模型是 IndexViewModel,我通过将返回结果路由到索引 View 来修复它。
if (!ModelState.IsValid)
{
return View(nameof(Index),model);
}
不确定这是否是 Asp.Net 默认应用程序团队打算重新路由的地方,但这就是我要进行的修复(kludge)。有更好的解决方案欢迎评论。
关于c# - 默认的 Asp.Net Core web 模板带有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47532199/