问题
Someone please help out: I added this statement to my partialview login page
@HttpContext.Current.Session["userID"] = User.Identity.GetUserId().ToString();
and receive errors below:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1525: Invalid expression term '='
Source Error:
Line 66: #line default Line 67: #line hidden Line 68: EndContext("~/Views/Shared/_LoginPartial.cshtml", 73, 37, false); Line 69: Line 70:
回答1:
As you try to perform assignments in Razor, it requires to wrap the code in curly brackers
@{ HttpContext.Current.Session["userID"] = User.Identity.GetUserId().ToString(); }
回答2:
I just use User.Identity.GetUserId directly instead of session variable.
Thank you all.
Still, I appreciate it if someone can explain what that error means though.
来源:https://stackoverflow.com/questions/34803589/getting-errors-with-session-variable-in-partialview-mvc