ASP.NET MVC – ways to store data between requests.

On the client:

  • Cookie

On the server:

  • Cache (make sure to use user specific key to avoid collisions)
  • Some back-end storage (such as a database)
  • ASP.NET Session
  • ViewData – dictionary that accessible by string keys
  • ViewBag – ViewData wrapper that allows to create dynamic properties.

In addition we can use TempData that is basically dictionary that is used to store data between controllers actions. The value of  TempData persists only in the current and the subsequent requests only. We should also check it for null and it requires typecasting of complex objects.

Share this post:Tweet about this on TwitterShare on Facebook0Share on LinkedIn0Share on Google+0Share on Reddit0Email this to someoneDigg this