Sunday, 31 January 2010

ViewData vs. TempData

ViewData and TempData are both used to pass data from Controller into View in ASP.NET MVC model. This article is trying to point out their's difference.

ViewData is only available in current request but TempData, which stored in user session, whose life will be around current and the right next requests. In the other word, if you are trying to share data between two continued request or during a redirection then TempData will be your choice.

BTW, to ensure you get the data by either ViewData or TempData you can use the code
<%=ViewData["name"] ?? TempData["name"]%> 

No comments: