Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何解决错误CS1525无效表达式项'=';?_C#_Asp.net_Asp.net Core_Compiler Errors_Scaffold - Fatal编程技术网

C# 如何解决错误CS1525无效表达式项'=';?

C# 如何解决错误CS1525无效表达式项'=';?,c#,asp.net,asp.net-core,compiler-errors,scaffold,C#,Asp.net,Asp.net Core,Compiler Errors,Scaffold,这是register类中post方法的代码: public async Task<IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= Url.Content("~/Account/feeds"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).

这是register类中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();
    }
PostAsync上的公共异步任务(字符串returnUrl=null) { returnUrl???=Url.Content(“~/Account/feeds”); ExternalLogins=(wait _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if(ModelState.IsValid) { var user=新应用程序用户{ UserName=Input.UserName, Email=Input.Email, DateOfBirth=Input.DOB, 性别=投入。性别 }; //这个也是 //注意ma3aml dbcontext.add(user)batteekh w 3amal save。。 var result=await\u userManager.CreateAsync(用户,输入,密码); if(result.successed) { _logger.LogInformation(“用户使用密码创建了一个新帐户”); /*var code=wait_userManager.GenerateEmailConfirmationTokenAsync(用户); code=WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl=Url.Page( “/Account/ConfirmEmail”, pageHandler:null, 值:new{area=“Identity”,userId=user.Id,code=code}, 协议:请求。方案); 等待_emailSender.sendmailasync(Input.Email,“确认您的电子邮件”, $“请确认您的帐户。”)*/ 如果(_userManager.Options.SignIn.RequiredConfirmedAccount) { 返回RedirectToPage(“RegisterConfirmation”,new{email=Input.email}); } 其他的 { wait _signInManager.SignInAsync(用户,ispersist:false); 返回LocalRedirect(returnUrl); } } foreach(result.Errors中的变量错误) { AddModelError(string.Empty,error.Description); } } //如果我们走到这一步,有些东西失败了,重新显示形式 返回页(); } 错误为“无效表达式项“=”,它指向 return???=Url.Content(“~/Account/feeds”); 知道该类是脚手架项目,如何解决此错误

谢谢。

??=是最合适的。那个是语法糖。它增加了C#7.3,改进了8.0

请注意,C#版本完全是一个编译器。它与目标框架无关。然而后端框架确实很重要,从某种意义上说,真正的命令行编译器VS is remoting可能还不支持新的C#方言:


空合并赋值运算符(
??=
)是C#8中引入的一项功能。您的项目可能没有正确地针对该语言版本,或者可能无法针对它

您可以相当容易地获得与此操作符所做的基本相同的功能,尽管它有点冗长

returnUrl = returnUrl ?? Url.Content("~/Account/feeds");
您还可以检查该值是否为null,然后将其赋值

if(returnUrl == null)
    returnUrl = Url.Content("~/Account/feeds");

你的项目目标是C#8吗?您正在使用Visual Studio 2019吗?请不要发布代码的图片,而是将代码粘贴到您的问题中。请参阅@JonathonChase yes im使用VS 2019请以文本形式发布代码,而不是图像。也最好是一个最小的、完整的、可验证的示例。不过,我同意乔纳森的观点,看起来你尝试使用的语法是sugar,这只是在后来的C#版本中才引入的。Done@Christopher-hmm。。项目正常进行时突然出现了这个错误。。你认为应该怎么做?我相信这是“空合并赋值”运算符,是C#8特性。@JonathonChase那么我认为你是对的。我得查一下。同样在VS2019中,您使用的C#版本似乎也存在问题,具体取决于目标框架。因此,语言版本是最可能的原因。