I am using ASP.NET MVC 3 to build a web application.
What I am trying to do is pass values between two controllers, though there are many ways to do this I am particular interested in using TempData
for this.
public ActionResult Action1()
{
string someMessage;
Test obj = SomeOperation();
if(obj.Valid)
{
someMessage = obj.UserName;
}
else
{
someMessage = obj.ModeratorName;
}
TempData["message"] = someMessage;
return RedirectToAction("Index");
}
public ActionResult Index()
{
ViewBag.Message = TempData["message"]
return View();
}
So is the use of TempData
here correct ? I mean under best programming practices is this correct way of using TempData
?
In what real time cases should TempData
be used ?
Note : I have gone through the following links
- When to use TempData vs Session in ASP.Net MVC
- http://www.gregshackles.com/2010/07/asp-net-mvc-do-you-know-where-your-tempdata-is/
Thanks
Customer XXX deleted
is what I want to display and this XXX I am passing using TempData. Thanks for clearing this for me. – Chiclayo