c# - In my controller class, where do I keep a variable that is associated with a page? -
allow me explain situation in more detail. have controller like
public class answerscontroller : controller { // ... private guid _pid; // ... [httpget] public actionresult fillout ( guid pid ) { this._pid = pid; // ... } // ... } which attempt @ stored variable _pid associated view invoked fillout when ajax call view invokes method on controller uses variable
[httppost] public actionresult submitanswers ( list<answersubmission> answers ) { // ... this._db.submitanswers(answers, this._pid); i have there instead of passing page , posting back. resulting in errors due this._pid not being set.
where flaw in reasoning? need pass variable view? thought new instance of controller associated page.
the flaw in reasoning each query server creates new controller, each time _pid null.
you have choice , fast , dirty choice: store data in physical storage (file, db, etc) or make property static , shared among instances.
but beware, static field can emptied times because appdomain can unloaded server.
Comments
Post a Comment