Is there a way in ASP.NET MVC2 to return redirectToAction when passing a parameter?

I want to do something, for example, edit my email address on the profile page, and then return to the home page, saying that it was successful - just like stackoverflow does when you get answers or earn a new icon.

+3
source share
2 answers

Try using TempData:

public ActionResult PostUserEmail(string email)
{
    TempData["Message"] = 'Email address changes successfully';
    return RedirectToAction("HomePage");
}

public ActionResult HomePage(string email)
{
    ViewData["Message"] = TempData["Message"];
    return View();//Use ViewData["Message"] in View
}

TempData["Message"]will remain after the redirect. TempData is saved in the next query, and then it disappears.

+3
source

I do not use MVC2, but in MVC1 you can do something like:

return RedirectToAction("HomePage", new { msg = "your message" });

public ActionResult HomePage(string msg)
{
   // do anything you like with your message here and send it to your view
   return View(); 
}

. , , . , (TempData [ "stringLookup" ], ViewData [ "tringLookup" ]), . , intellisense.

+1

Source: https://habr.com/ru/post/1742065/