在JavaScript中访问会话变量 [英] Access Session variables in JavaScript

查看:119
本文介绍了在JavaScript中访问会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问会话变量在JavaScript中asp.net MVC应用程序。我已经找到一种方法来做到这一点在ASPX视图引擎,但不是在剃刀。

I wanted to access a session variable in javascript in asp.net mvc application. I have found a way to do it in aspx view engine but not in razor.

请告诉我一个方法来访问会话变量

Please tell me a way to access the session variables

推荐答案

您可以这样来做了字符串变量:

You can do it this way for a String variable:

<script type="text/javascript">
    var someSessionVariable = '@Session["SomeSessionVariable"]';
</script>

或者这样,如果它的数字:

Or like this if it's numeric:

<script type="text/javascript">
    var someSessionVariable = @Session["SomeSessionVariable"];
</script>

这实在不是一个很干净的做法,虽然,需要内联JavaScript,而不是使用脚本文件。要小心,不要得意忘形与此有关。

This is really not a very clean approach though, and requires inline JavaScript rather than using script files. Be careful not to get carried away with this.

这篇关于在JavaScript中访问会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆