Hi tsakumar81,
Child actions follow a different Model View Controller lifecycle than parent actions.
So they do not share ViewBag or ViewData.
Alternate way you can pass it as model.
Refer below code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
NorthwindEntities entities = new NorthwindEntities();
ViewBag.Orders = (from order in entities.Orders.Take(2)
select order).ToList();
return View(from customer in entities.Customers.Take(1)
select customer);
}
[ChildActionOnly]
public ActionResult Details(List<Order> orders)
{
return PartialView("Details", orders);
}
}
View
@model IEnumerable<Customer>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h4>Customers</h4>
<hr />
<table cellpadding="0" cellspacing="0" id="CustomerGrid">
<tr>
<th>CustomerID</th>
<th>Contact Name</th>
<th>Orders</th>
</tr>
@foreach (Customer customer in Model)
{
<tr>
<td>@customer.CustomerID</td>
<td>@customer.ContactName</td>
<td>@Html.Action("Details", new { Orders = ViewBag.Orders })</td>
</tr>
}
</table>
</body>
</html>
Partial View
@model IEnumerable<Order>
<table>
@foreach (Order order in Model)
{
<tr>
<td>@order.OrderID</td>
<td>@order.ShipName</td>
</tr>
}
</table>
Screenshot