ViewModel Vs ViewData Vs ViewBag Vs TempData Vs Session In MVC

ASP.NET MVC, Web Development

Reference Site: My Tech Bits

  • Use ViewModel instead of ViewData and ViewBag. As ViewModel provides compile time error checking and intellisense support in Visual Studio IDE, the code will be clean and less error prone.
  • Use TempData for error handling. On capturing and exception or error, pass the error details using TempData to the error page, to display the proper error details.
  • Use Session to check the user’s login status and permission level.
  • Try to avoid using TempData and Session, if your web application is in webfarm environment.