Reputation: 21989
This solution has evaded me all day. I am getting data from my database, but I would like to save the data somewhere as opposed to going to the database for every page. How do I do this?
I retrieve the data from my controller...
public ActionResult Inquiry(string Num, DateTime Date)
{ ...
Bill myBill = new Bill(Num, Date, myConnections);
//This is where I am trying to store my data...
return View("Inquiry", myBill);
}
Then on my Inquiry page...
public ActionResult Summary(string Num, DateTime Date)
{ ...
Bill myBill = new Bill(Num, Date, myConnections);
//... Data get retrieved here :(
return View("Summary", myBill);
}
It is enough data to look away from storing in a session. Is it possible to save to the Model forlder and just use an inherit on the aspx page?
I am a young bud in the programming world, worse .NET MVC
I should be able to figure out where to go from there. Any ideas?
Upvotes: 2
Views: 3090
Reputation: 40162
Assuming I understood your question correctly:
You could cache the item. Assign the a unique key to the cache object (Cache["uniquekey"]), then pass that unique key to your other action.
Have your action look up that object from the cache and send it as the model.
Here is an article about caching from the 4 Guys from Rolla, while here is an official ASP.NET learning video about caching.
Note: Be sure you specify expiration date on the cached object.
Upvotes: 2
Reputation: 945
If these are two actions on the same controller, and you are essentially posting the model back to the controller on submit (which is only a guess of what you may be doing), then you can use the form values collection and updateModel method, or even use a strongly typed action like this(ish):
public ActionResult Inquiry(string Num, DateTime Date)
{ ...
Bill myBill = new Bill(Num, Date, myConnections);
//This is where I am trying to store my data...
return View("Inquiry", myBill);
}
public ActionResult Summary(Bill bill)
{
//... do stuff
return View("Summary", bill);
}
This way you are getting that information from a natural source; the incoming bill. You can process on this, save it, change it around, throw it in another model but then dump it back out the the view with out necessarily reloading it.
I am new to aspnet mvc too, and most of the times I struggle with data ins and outs, there is something I am missing architecture wise.
Scott Gu's nerddinner chapter is exceedingly helpful in figuring some of it out.
Upvotes: 0