---
title: "Pass and Get Data by ViewBag in MVC"  
description: "Pass and Get Data by ViewBag in MVC"  
author: "Anonymous User"  
published: 2017-12-16  
updated: 2017-12-16  
canonical: https://www.mindstick.com/forum/34406/pass-and-get-data-by-viewbag-in-mvc  
category: "c#"  
tags: ["asp.net mvc", "mvc", "mvc4", "razor"]  
reading_time: 1 minute  

---

# Pass and Get Data by ViewBag in MVC

Hi,

I am new in MVC. I want to [pass data](https://www.mindstick.com/forum/351/how-to-pass-data-from-controller-to-ascx-page) in [ViewBag](https://www.mindstick.com/forum/155739/define-viewbag-in-mvc) from the [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) and Getting data from ViewBag in View. [Please suggest](https://answers.mindstick.com/qa/43506/please-suggest-the-bathing-date-at-kumbh) me a better way to achieve this task.

## Replies

### Reply by Hemant Patel

Hi Shaan,

I tried to give you the better way to accomplish your task.

First, we go to Controller section. And write code for Pass [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) into ViewBag in a controller method.

```
 ViewBag.YourVariableName="Value you want to send from controller to view";
```

Now we go to View section in our MVC project and trying to get data of ViewBag. Here is the code for getting data of ViewBag,

```
<div>@ViewBag.YourVariableName</div>
```

I think its helpful for you...

\


---

Original Source: https://www.mindstick.com/forum/34406/pass-and-get-data-by-viewbag-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
