Wednesday, July 13, 2011

ViewBag is not living in redirected action

ViewBag - a place holder between action and view - is living in one response. In other words, ViewBag is not living in redirected action despite the fact Rails' flash go living. Then, what should we use? It is TempData

Controller#Edit action
ViewBag.Hello = "Hello ViewBag";
TempData["Hello"] = "Hello TempData";
return RedirectToAction("Index");

Index view
ViewBag : @ViewBag.Hello<br />
TempData : @TempData["Hello"]<br />

result

No comments:

Post a Comment