2

I am trying to store information that can be shared from one screen to another. I am considering storing the data like this:

Session["x"] = "x";

I saw another person was considering this for MVC. Please excuse my lack of knowledge here but does this mean the data for "x" will be stored locally or on the server?

I would like to access this data from javascript / jQuery? Is this possible? Are there any disadvantages to storing data like this?

thanks,

Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427

3 Answers3

3

Session data is get stored on server so there is no direct way to get data from server using jquery/javascript

you can query session data by making ajax call to server............

Check this : How to get asp.net Session value in jquery method? its related to asp.net and C# but this might help you to understand

Community
  • 1
  • 1
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
3

you can write script in razor file, and then access Session["x"]

<script type="text/javascript">
    $(function () {
        alert(@Sesion["x"]);
    })
</script>
Artur Keyan
  • 7,643
  • 12
  • 52
  • 65
2

As you are mentioning screens, I think you are working with Client side web sessions, which is realized through cookie.

You could archieve sharing data in one client browser across multiple screens from one domain using cookies.

I suggest using the jquery.cookie plugin as a practical solution

To set a cookie

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });

To get a cookie

$.cookie('the_cookie'); 

To delete the cookie

$.cookie('the_cookie', null);
steveyang
  • 9,178
  • 8
  • 54
  • 80