C # 6 Syntax in Razor View
<input type="hidden" value="@ViewData["LoginProvider"]?.ToString() ?? null" /> When the ViewData value is null, it does half-conversion , and the hidden field contains the value ?.ToString() ?? null ?.ToString() ?? null
I am sure I have included C # 6:
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"> <providerOption name="CompilerVersion" value="v4.0" /> </compiler> Why?
Have a problem with ?? operator, the left value is a string and the right value is null, so this is not the correct syntax. In addition, since there is an assignment operation, you need to enclose them in parentheses.
You can try the following:
<input type="hidden" value="@(ViewData["LoginProvider"]?.ToString() ?? "")" />