When working with ASP.NET MVC applications, you need to pass the data from controller action methods to the view. There are various techniques to do that, and these are through ViewData, ViewBag, and TempData.
Passing data to a view through a model or view model class is recommended and there are times where you need to pass arbitrary data to the view. Like when you need to pass a success or error message from a controller to a view so it can be rendered by the browser. Since the data is not a part of the model, you need some mechanism to pass it to the view.
This article explain the techniques and the difference with these three.
Read the rest of the tutorial here:Â http://www.dotnetbips.com/articles/36941654-8bd4-4535-9226-ddf47841892f.aspx