0

I am using PRG pattern for form submission in mvc. But In most of the sites suggested me to use temp data in PRG instead of view data. But I don't know how to judge this.

View bag and view data Lives only during the current request from controller to view and Temp data also Lives only during the current request from action to action or controller to another controller.

Can we use View data instead of Temp data for PRG pattern ?

Why we need to use temp data instead of view bag, view data ?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Possible duplicate of http://stackoverflow.com/questions/173159/difference-between-viewdata-and-tempdata or check http://www.codeproject.com/Articles/476967/WhatplusisplusViewData-2cplusViewBagplusandplusTem – Nitin Varpe Jan 27 '14 at 11:56

1 Answers1

0

in prg pattern you redirect after a successful form submission wheres as ViewData is saved after a redirect whereas temp is saved using the same storage that session uses.

what i mean by this is if you have saved any data in ViewData like ViewData.CustomerId = 67; it wont be available to you after the form is submitted and the user is redirected to another action/controller

where as if you save data in TempData it will be saved for at least the time where you access it once

Parv Sharma
  • 12,581
  • 4
  • 48
  • 80