Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.18/5 (3 votes)
See more:
Hi all,
I have 5 views and i want to declare 1 variable (global) that 5 views can use that variable.
That global variable can store list of customer (Customer Code and Customer Name).
Note:
When user log in, i want to assign customer info to that variable and those value will be use in in 5 views

Thanks

TONY
Posted

1 solution

In a web application, like an ASP.NET MVC application, global can have several meanings, actually you need to define the scope. You have the possibility to define application scope global objects, but in your case it is clear that you want to keep this value only in a session scope. If this data is large, you should use some persistence, like reloading the content from a database. But ff this is not a big object, you can use the session storage.
Have a look here:
http://www.campusmvp.net/blog/how-to-manage-session-variables-like-a-pro[^]
MVC Test Driven Development: Session Variables[^]
Understanding Session Management Techniques in ASP.NET[^]
http://blogs.msdn.com/b/aspnetue/archive/2010/09/17/second_2d00_post.aspx[^]
And be aware, that by default, you don't have session object in the controller constructor.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900