c# - Asp.net mvc set session variable in javascript - Stack Overflow

I am trying to set session value in javascript :session value 5400remainingSeconds value 5399@Ses

I am trying to set session value in javascript :

//session value 5400
//remainingSeconds value 5399
@Session["remain-seconds"] = remainingSeconds;

But i am getting the following error:

invalid left-hand side in assignment

Is it possible to set session variable inside javascript?

I am trying to set session value in javascript :

//session value 5400
//remainingSeconds value 5399
@Session["remain-seconds"] = remainingSeconds;

But i am getting the following error:

invalid left-hand side in assignment

Is it possible to set session variable inside javascript?

Share Improve this question edited Feb 1, 2016 at 20:32 inverted_index 2,4371 gold badge23 silver badges46 bronze badges asked Feb 1, 2016 at 20:22 ucnobi ucnobiucnobi ucnobi 2551 gold badge6 silver badges16 bronze badges 2
  • 2 Sessions cannot be accessed by JavaScript – jasonwarford Commented Feb 1, 2016 at 20:25
  • @jasonwarford Are you sure ? – ucnobi ucnobi Commented Feb 1, 2016 at 20:26
Add a ment  | 

1 Answer 1

Reset to default 2

No, session variables are server side. You'd have to have a little ajax call to talk to the server to set it. There are plenty of examples of this via google searches. You can see one example here.

For a one-time evaluation (on the server, before it hits the client), you can set it (sort of) in the code section of your script, but I think that's different from what you're asking to do. See this thread.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744909654a4600469.html

相关推荐

  • c# - Asp.net mvc set session variable in javascript - Stack Overflow

    I am trying to set session value in javascript :session value 5400remainingSeconds value 5399@Ses

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信