Getting errors with session variable in partialview MVC

北战南征 提交于 2019-12-11 12:53:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!