Razor MVC3保持全局变量集返回视图

Bad*_*ral 3 c# asp.net-mvc

我有一个全局字符串变量,我在一个操作后设置(按下提交按钮),然后我想在我按下另一个按钮时访问相同的字符串,目前我正在做类似的事情

GlobalVariable = "blah";
return View();
Run Code Online (Sandbox Code Playgroud)

再次访问此操作的最佳做​​法是什么?我想指出它是同一页面(index.cshtml)

谢谢!

Dis*_*ame 7

如果是每用户值,请使用:

Session["MyKey"] = "MyValue"; // save the value
var myValue = (string) Session["MyKey"]; // retrieve the value
Run Code Online (Sandbox Code Playgroud)

如果所有用户的一个值使用此值:

Application["MyKey"] = "MyValue"; // save the value
var myValue = (string) Application["MyKey"]; // retrieve the value
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.