【发布时间】:2020-05-11 03:05:52
【问题描述】:
这是注册类中post方法的代码:
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
returnUrl ??= Url.Content("~/Account/feeds");
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
if (ModelState.IsValid)
{
var user = new ApplicationUser {
UserName = Input.username,
Email = Input.Email,
DateOfBirth = Input.DOB,
Gender = Input.Gender
};
//this one too
//notice ma3aml dbcontext.add(user) batteekh w 3amal save..
var result = await _userManager.CreateAsync(user, Input.Password);
if (result.Succeeded)
{
_logger.LogInformation("User created a new account with password.");
/*var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { area = "Identity", userId = user.Id, code = code },
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");*/
if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
return RedirectToPage("RegisterConfirmation", new { email = Input.Email });
}
else
{
await _signInManager.SignInAsync(user, isPersistent: false);
return LocalRedirect(returnUrl);
}
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}
//If we got this far, something failed, redisplay form
return Page();
}
错误是“无效的表达式术语'='”,它指向行 return ??=Url.Content("~/Account/feeds"); 知道这个类是一个脚手架项目,我该如何解决这个错误??
谢谢。
【问题讨论】:
-
您的项目是否面向 C# 8?你在使用 Visual Studio 2019 吗?
-
请不要张贴您的代码图片,实际上是将代码粘贴到您的问题中。见how to ask a question
-
@JonathonChase 是的,我正在使用 VS 2019
-
请将代码发布为文本,而不是图像。也最好是一个最小的、完整的、可验证的例子。不过我同意乔纳森的观点,看起来您尝试使用仅在更高版本的 C# 版本中引入的语法糖。
-
完成@Christopher 嗯.. 项目正常构建突然出现这个错误.. 你认为应该怎么做?
标签: c# asp.net asp.net-core compiler-errors scaffold