Transferring a useful message from the controller to another redirected controller

I want to do RedirectToAction after the user clicks a button. Before forwarding, I store the information in a variable. In the end, after I redirected the action, I want to show useful information. I tried this:

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

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

+5
source share
1 answer

You can use TempData.

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

It is saved in the session, but after its access it will be deleted.

Here are some useful links.

Data Transfer in an ASP.NET MVC Application

Difference between ViewData and TempData?

+18
source

All Articles