开发者

Global data across MVC controller

I have number of action methods in my controller that retrieve data from web services or database. Along them there are other action methods in the same controller that use that data. As I would love to prevent unnecessary data retrieval I'd like to know what would be the best practice to share that data with the other methods without using cookies or sessions?

Is it acceptable to use global properties in the controlle开发者_C百科r?


use Cache.Insert to store the data server side - it's your simplest method of achieving this. Be aware though of the serialization impact on large objects.


Do you want to use the data across multiple requests? Then I would recommend session. Or do you have a couple of partial views and keep the date only for one request? Then you could use the ViewBag. You mention multiple action methods: are they all in the same controller? Even then it doesn't help: Every request creates a new Controller instance, you can not share the date through properties of the controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜