prevent repopulating viewdata
Having populated a ViewData, is it possiblie to use that ViewData collecti开发者_如何学Con from multiple action methods within a controller without the need to repopulate it?
No, ViewData
is not intended to be used that way. It is only a temporary shared storage between a controller action and a view. It allows the controller to pass some model to the view. From design perspective ViewData
should not be read by the controller action, it should only be written to.
You could use the Session
object if you want to store objects between multiple requests or TempData
(which internally uses Session) to store data between two requests.
yes you can if you store the data in some persistent storage between calls (like Session or some sort of cache for example). though i don't recommend that approach sometimes is necessary for long lived data that is needed everywhere and does not change very often.
精彩评论