---
title: "How to send data from controller to view page in asp.net MVC?"  
description: "How to send data from controller to view page in asp.net MVC?"  
author: "Kalin"  
published: 2022-03-10  
updated: 2022-03-10  
canonical: https://www.mindstick.com/forum/156903/how-to-send-data-from-controller-to-view-page-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 4 minutes  

---

# How to send data from controller to view page in asp.net MVC?

How to send [data from controller](https://www.mindstick.com/forum/351/how-to-pass-data-from-controller-to-ascx-page) to view [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) in [asp.net MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc)? also [define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) how many way to send data from [controller to view](https://www.mindstick.com/forum/12918/pass-an-object-from-controller-to-view-with-asp-dot-net)?

## Replies

### Reply by roj ldee

Like someone said your names are colliding. If you use Fiddler you'll see what you post looks like FirstName='asdf' LastName='asdf' FirstName='123' LastName='123' , which property goes with which item in the list<t> ? MVC can't figure it out either and will be empty at the break point.

If your html names were indexed something like <input name='collection[0].FirstName.. and name='collection[1].FirstName.. you should actually get the correct values.

\

### Reply by roj ldee

Like someone said your names are colliding. If you use Fiddler you'll see what you post looks like FirstName='asdf' LastName='asdf' FirstName='123' LastName='123' , which property goes with which item in the list<t> ? MVC can't figure it out either and will be empty at the break point.

If your html names were indexed something like <input name='collection[0].FirstName.. and name='collection[1].FirstName.. you should actually get the correct values.

Maybe it's too early but I'm having trouble understanding what you're trying to do overall. I'd recommend not sending the whole list<t> back to the controller. Wouldn't it be better to create a separate view for editing the items? Or even putting that edit view in a partial to display in a modal?

### Reply by Steilla Mitchel

**Pass [Data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) to [View](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) in [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [MVC](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc):**

We have three ways to send data from controller to view in asp.net mvc application. Those are

1- TempData

2- ViewBag

3- ViewData

## 1- TempData:

Temp data is used to send data from controller to controller or controller to view in asp.net mvc. it has short life and it required typecasting. It is used to pass data from current active page to next page. TempData is a dictionary object, it is derived from TempDataDictionary class.

## Exp-

```
    //     Gets or sets the dictionary for temporary data.// Returns:
//     The dictionary for temporary data.
public TempDataDictionary TempData { get; set; }
```

Here is controller page to return a message to view using TempData,

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mindstick.Controllers
{
public class DemoController : Controller
{
public ActionResult Index()
{
TempData['Demo'] = 'hello Tempdata';
return View();
}
}
}
```

Here we create a view page 'Index.cshtml' to show the message

```
@{
    ViewBag.Title = 'Index';
 }
 <h2>Index</h2>
@TempData['Demo']
```

## 2- ViewBag :

ViewBag is used to pass data from controller to view in asp.net mvc. It does not need to typecasting and it contains null value when it redirection occures. **\**

## Exp-

```
// Gets the dynamic view.// Returns:// The dynamic view.[Dynamic]
public dynamic ViewBag { get; }
```

Create model page to send data to view

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mindstick.Controllers
{
public class DemoController : Controller
{
public ActionResult Index()
{
ViewBag.msg = 'hello ViewBag';
return View();
}
}
}
```

Create View to execute messate

```
@{
ViewBag.Title = 'Index';
}
<h2>Index</h2>
@ViewBag.msg
```

## 3- ViewData:

ViewData is also like TempData. It also derived from ViewDataDictionary and it also need to typecasting.

create model page to return message to view using ViewData

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mindstick.Controllers
{
public class DemoController : Controller
{
public ActionResult Index()
{
ViewData['msg'] = 'hello Viewdata';
return View();
}
}
}
```

Now create View page to show message of ViewData

```
@{
ViewBag.Title = 'Index';
}
<h2>Index</h2>
@ViewData['msg']
 
```


---

Original Source: https://www.mindstick.com/forum/156903/how-to-send-data-from-controller-to-view-page-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
