[英]How to solve Error CS1525 Invalid expression term '='?
This is the code of the post method in the register class :这是注册类中 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();
}
The error is "Invalid expression term '=' " and it points to the line of return ??=Url.Content("~/Account/feeds");错误是“Invalid expression term '='”,它指向返回行 ??=Url.Content("~/Account/feeds"); How can I solve this error knowing that this class is a scaffolded item ??
知道这个类是一个脚手架项目,我该如何解决这个错误?
Thanks.谢谢。
??= is the Null Coalescing Operator . ??= 是空合并运算符。 That one is syntax sugar.
那个是语法糖。 It was added with C# 7.3 and improoved with 8.0.
它是在 C# 7.3 中添加的,并在 8.0 中进行了改进。
Note that the C# Version is entirely a compiler thing.请注意,C# 版本完全是一个编译器。 It has nothing to do with the Target Framework.
它与目标框架无关。 However the Backend Framework does mater, in the sense the the real commandline compilers VS is remoting might not yet support a new Dialect of C#:
但是后端框架确实很重要,从某种意义上说,VS 远程处理的真正命令行编译器可能还不支持新的 C# 方言:
https://www.c-sharpcorner.com/article/which-version-of-c-sharp-am-i-using-in-visual-studio-2019/ https://www.c-sharpcorner.com/article/which-version-of-c-sharp-am-i-using-in-visual-studio-2019/
The Null Coalescing Assignment operator ( ??=
) is a feature introduced in C# 8. It appears that your project may not be correctly targeting this version of the language, or perhaps be unable to target it.空合并赋值运算符 (
??=
) 是 C# 8 中引入的一项功能。您的项目似乎没有正确定位该语言版本,或者可能无法定位它。
You can get what's essentially equivalent functionality to what this operator does fairly easily, though it's a bit more verbose.您可以相当容易地获得与此运算符所做的基本等效的功能,尽管它有点冗长。
returnUrl = returnUrl ?? Url.Content("~/Account/feeds");
You could also just check if the value is null, and then assign to it.您也可以只检查值是否为空,然后分配给它。
if(returnUrl == null)
returnUrl = Url.Content("~/Account/feeds");
Severity Code Description Project File Line Suppression State Error (active) CS1525 Invalid expression term '=' EmployeeMngmnt C:\\Users\\LAP3\\source\\repos\\EmployeeMngmnt\\Views\\Home\\Details.cshtml严重性代码 描述 项目文件行抑制状态错误(活动) CS1525 无效表达式术语 '=' EmployeeMngmnt C:\\Users\\LAP3\\source\\repos\\EmployeeMngmnt\\Views\\Home\\Details.cshtml
I have same error , I am using vs2019.我有同样的错误,我正在使用vs2019。 please help me.
请帮我。 this is my code
这是我的代码
@{
Layout = "~/Views/Shared/_layout.cshtml";
}
what is wrong with this code?## Heading ##这段代码有什么问题?##标题##
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.