Can I send tempdata to a redirected page? if yes how? if no, any alternative?
TempData is used to pass data from current request to subsequent request (means redirecting from one page to another). It's life is very short and lies only till the target view is fully loaded. But you can persist data in TempData by calling Keep() method.
To pass the strongly typed data from Controller to View using TempData, we have to make a model class then populate its properties with some data and then pass that data to TempData as Value and selecting Key's name is the programmer's choice.
TempData is used to transfer data from view to controller, controller to view, or from one action method to another action method of the same or a different controller. TempData stores the data temporarily and automatically removes it after retrieving a value. TempData is a property in the ControllerBase class.
In one sentence: TempData are like ViewData with one difference: They only contain data between two successive requests, after that they are destroyed. You can use TempData to pass error messages or something similar.
You can use TempData to persist data from one request to another when using Redirect()
and RedirectToAction()
This MSDN article explains it all.
If you want your page to display this data then you just need to pass it to your view from your action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With