0

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 controller?

4

2 に答える 2

0

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.

于 2011-04-20T22:05:45.627 に答える
0

Cache.Insert を使用してデータ サーバー側を格納します。これは、これを実現する最も簡単な方法です。大きなオブジェクトに対するシリアル化の影響に注意してください。

于 2011-03-23T18:03:09.880 に答える