c# - Class variables MVC 2 application -
i don't understand doing wrong when setting class variables. instance, when call sethelloworld(), helloworld is: hello world returned. when call gethelloworld(), helloworld is:, returned. why helloworld behaving empty string after being set?
public class homecontroller : controller { string helloworld; public string sethelloworld(){ helloworld = "hello world"; return "helloworld is: " + helloworld; } public string gethelloworld() { return "helloworld is: " + helloworld; } }
the instance of controller created per request, no state kept. it's part of stateless nature of web.
you can consider putting in session state or http cache if need persisted multiple requests.
Comments
Post a Comment