gpt4 book ai didi

c# - Razor MVC3 在返回 View 时保持全局变量集

转载 作者:行者123 更新时间:2023-11-30 13:17:15 24 4
gpt4 key购买 nike

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

GlobalVariable = "blah";
return View();

再次访问它的最佳做法是什么。我想指出这是同一页(index.cshtml)

谢谢!

最佳答案

如果它是每个用户的值,请使用:

Session["MyKey"] = "MyValue"; // save the value
var myValue = (string) Session["MyKey"]; // retrieve the value

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

Application["MyKey"] = "MyValue"; // save the value
var myValue = (string) Application["MyKey"]; // retrieve the value

希望这对您有所帮助。

关于c# - Razor MVC3 在返回 View 时保持全局变量集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12426627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com