kamil.wydrzycki
kamil.wydrzycki

Reputation: 451

How do I store data between requests in ASP.NET MVC?

My application reads barcodes from a USB scanner. I treat them as tokens and then build commands from those tokens. There may be a situation that I need 2 or more reads before I can create a command. I need to store previous reads in some way. How can I keep some data between request? I do not to use that tokens in my view.

Only results of commands may be displayed in the view.

Upvotes: 15

Views: 18404

Answers (2)

Alistair Findlay
Alistair Findlay

Reputation: 1154

The TempData dictionary is ideal for storing data between controller actions. It's most commonly used in the Post/Redirect/Get pattern but could apply here.

This is a good article to read about it: http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html

Upvotes: 15

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Here are a couple of possibilities that come to mind:

On the client:

  • Cookie
  • Hidden fields

On the server:

  • Cache (make sure to use user specific key to avoid collisions)
  • Some backend storage (such as a database)
  • ASP.NET Session

Upvotes: 9

Related Questions