Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing useful message from a controller to another redirected controller

I want to make a RedirectToAction after the user clicks a button. Before I redirect, I store the information into a variable. At the end, after I have redirected to action, I want to show some useful information. I tried this:

ViewBag.message = "User with ID = " + id + " was changed status to verified.";

But the data will be flushed after redirection. Is there any other way to achieve this?

like image 946
1myb Avatar asked Aug 08 '11 05:08

1myb


1 Answers

You can use TempData.

TempData["message"] = "User with ID = " + id + " was changed status to verified.";

It is stored in session but after you access it, it will be removed.

Here are some useful links

Passing Data in an ASP.NET MVC Application

Difference Between ViewData and TempData?

like image 170
Eranga Avatar answered Oct 26 '22 08:10

Eranga