Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No 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
Posted
Comments
Sergey Alexandrovich Kryukov 20-Oct-13 2:00am    
Using any global variables is a bad idea.
—SA

Using global variables is often a bad thing, its usually against reusability. What you want is to share data between 5 different objects. Then create your data object and pass the reference of this data object to all objects that need it and additionally you can keep a reference for yourself too. You can solve the destruction of the object by making it reference counted.
 
Share this answer
 
You have a couple of choices, but don't think of it as a variable, think of it as state. When you start thinking of it as state, you can start asking questions around storage, manipulation and/or access.

You could always use session state. You can access this from any controller or view. By default, this is stored in memory and lost when a user's session dies and/or your application pool is reset on the server. It is tied to a single user.

C#
Session["YourVariable"] = "Customer Name";


or

C#
Session["Customers"] = new List<customer>();</customer>


or similar.

Better would be to store this information in a database. There are many resources for this here on the site and across the web.

Cheers.
 
Share this answer
 

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