ViewData, ViewBag, and TempData

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:

Leave a Reply

Your email address will not be published. Required fields are marked *