Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TempData to redirected page?

Can I send tempdata to a redirected page? if yes how? if no, any alternative?

like image 230
coure2011 Avatar asked May 04 '11 14:05

coure2011


People also ask

Can TempData persist across action redirect?

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.

How do I pass TempData to view?

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.

Does TempData used to pass data from one page to another?

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.

What is difference between TempData and ViewData?

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.


1 Answers

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.

like image 65
David Glenn Avatar answered Nov 15 '22 07:11

David Glenn