How do I add to the TempData dictionary from a non controller class?
A:
To do so you'd need the current controller context, otherwise you cannot.
ViewContext.Controller.TempData["whatever"] = whatever
Kyle West
2009-02-03 13:19:10
+1
A:
Just don't do it :D. Everything needs to go through your controller, I know its a pain but that is the right way of doing it.
Al Katawazi
2009-02-03 16:00:08
I am using a strongly typed session state class, if a certain value does not exist I wasn't to add a message to the tempdata, so rather than repeat code on every single controller action that access this value I want to add the notification at that point.
Slee
2009-02-03 22:49:34
A:
You would have to pass the TempDataDictionary to the other class. I do this quite a bit and there is nothing wrong with it as long the other class is related to presentation (which it sounds like it is).
liammclennan
2009-02-04 03:17:25