I have a global string variable that I set after one action is made (submit button is pressed) and then I want to access that same string when I press another button, currently I am doing something like
GlobalVariable = "blah";
return View();
What is the best practice for accessing this again. I would like to point out it is the same page(index.cshtml)
Thanks!
If its a per user value, use this:
Session["MyKey"] = "MyValue"; // save the value
var myValue = (string) Session["MyKey"]; // retrieve the value
If its one value for all users use this:
Application["MyKey"] = "MyValue"; // save the value
var myValue = (string) Application["MyKey"]; // retrieve the value
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With