Created
June 12, 2013 04:24
-
-
Save vcavalcante/5762825 to your computer and use it in GitHub Desktop.
Demonstrando que o TempData continua vivo mesmo passando por uma action e chega na View.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<strong>@TempData["erro"]</strong> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : Controller | |
{ | |
public ActionResult Index(int Id) | |
{ | |
if (Id == 1) | |
{ | |
TempData["erro"] = "Descrição do erro"; | |
return RedirectToAction("Erro"); | |
} | |
return View(); | |
} | |
public ActionResult Erro() | |
{ | |
return View("erro"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ao invés da variavel
erro
receber oTempData
, você pode fazer o seguinte:TempData.Keep("erro")
assim o dado será persistido novamente até a próxima requisição.