---
title: "Passing Values From Controller to View in ASP.NET MVC"  
description: "You can use several concepts to pass values from controller to views or from one view to another view. If you want to pass temporary values (which is"  
author: "Anonymous User"  
published: 2011-12-10  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Passing Values From Controller to View in ASP.NET MVC

You can use several concepts to pass values from controller to views or from one view to another view. If you want to pass temporary values (which is only for one http request) then use TempData [collection](https://www.mindstick.com/articles/1718/collections-in-java) otherwise you can use ViewBag and ViewData collection.\

##### TempData

TempData is meant to be a very short-lived instance, and you should only use it during the current and the subsequent requests only! Since TempData works this way, you need to know for sure what the next request will be, and redirecting to another view is the only time you can guarantee this. Therefore, the only scenario where using TempData will reliably work is when you are redirecting. This is because a redirect kills the current request (and sends [HTTP status](https://www.mindstick.com/forum/160304/importance-of-http-status-codes-in-responses-to-httppost-methods-requests-in-dot-net-core-api) code 302 Object Moved to the client), then creates a new request on the server to serve the redirected view.

##### ViewData

Viewdata is the collection of state that is passed to a view. A view should get all the information it needs from the viewdata. It contains key/value pairs [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) some special [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties), such as Model. Viewdata is accessible on the controller as well. The controller is [responsible](https://answers.mindstick.com/qa/94149/who-is-one-of-the-responsible-person-for-the-department-of-space-dos) for filling the viewdata [dictionary](https://www.mindstick.com/articles/1500/hashtable-and-dictionary-in-c-sharp) with objects. When a view is executing, it will pull various object from viewdata while it is rendering. If an expected object is not present, then you will see the same type of exception present in any code using a dictionary collection in .Net.

##### ViewBag

ViewBag is a property of a Controller class that we generally used to [share data](https://www.mindstick.com/forum/160500/how-can-you-share-data-between-servlets) between Controller and View and. ViewBag objects is wrapper around ViewData that is used to create dynamic properties for ViewBag.

The [basic difference](https://www.mindstick.com/interview/2438/what-is-the-basic-difference-between-string-and-stringbuffer-object) between ViewData and ViewBag is that in ViewData instead creating dynamic properties we use properties of Model to transport the Model data in View and in ViewBag we can create dynamic properties without using Model data.

---

Original Source: https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
