Reputation: 77
For a website, consider this scenario:
and so on...
Currently, in step 5, I will use the ID to call the web service again for getting the required complex object.
Is there any correct/efficient way, without using TempData/ViewBag/ViewData, so that I can reuse the complex object, once it is created, in step 2?
Edit: Session is not allowed as well.
Upvotes: 0
Views: 1353
Reputation: 4895
Normally, for web application
, there're multiple options to store complex object depending on your need. I don't think there is a BEST way of doing, only the most suitable way and every solutions will come with PROS and CONS
SERVER SIDE
Session (I know you said cannot use session, but I just want to include it anyway): first option comes to mind, suitable for most web application. Since the modern web development are more on STATELESS, a lot of people want to avoid using Session
at all cost. However, there're some specific infrastructure configuration to support session in STATELESS application such as distributed session
or sticky session
or you can save the session in a dedicated server
or database
.
ANOTHER Dedicated server (Before anyone ask, I put it in the SERVER SIDE section even though it's another SERVER, but to me, whatever in our control is SERVER SIDE): a few options for you to choose here, first option could be to set up a cache server (Redis?) and retrieve/save using key (similar to session), or you can simply write an application to retrieve/save using your own logic.
Database: not a obvious choice, but database do support this kind of requirement
Other in-memory options (TempData, ViewBag, etc):
CLIENT SIDE
SUGGESTED SOLUTION
I hope I understand your issue correctly but in my opinion, you should not store complex object, simply store the ID of the complex object in place of your choice, and make a query every time you need the object. So that your object is always up-to-date and you don't waste resource to store the complex object.
Hope it helps you.
Upvotes: 2
Reputation: 7145
If you want to project an object to a certain view, then forget about any storage (TempData/ViewBag/ViewData/Session) and then post the same object to another controller, the best way you can re-construct your object is to store the object's properties as hidden <input>
controls.
Upvotes: 0