Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

equivalent of ASP.NET MVC TempData in ASP.NET

In ASP.NET MVC, there's a TempData which can pass data one time from one page to another. What's the equivalent for this in ASP.NET?

like image 566
rob waminal Avatar asked Jun 01 '11 08:06

rob waminal


People also ask

What is TempData in ASP.NET MVC?

What is TempData and How to Use in MVC? TempData is used to transfer data from the view to the controller, the controller to the view, or from an action method to another action method of the same or a different controller. TempData temporarily saves data and deletes it automatically after a value is recovered.

What is TempData in asp net core?

TempData. ASP.NET Core exposes the Razor Pages TempData or Controller TempData. This property stores data until it's read in another request. The Keep(String) and Peek(string) methods can be used to examine the data without deletion at the end of the request.

Which is better TempData or session in MVC?

TempData is ideal for short-lived things like displaying validation errors or other messages that we don't need to persist for longer than a single request. Session is ideal choice when we need to persist data for extended periods of time i.e. it is used to store data which is required throughout user session.

What is difference between ViewData and TempData in MVC?

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

There is no direct equivalent (that is, data that is only passed to the next page).

You can use Session and clear it out on the receiving page.

like image 116
Oded Avatar answered Oct 15 '22 08:10

Oded