Hi RamyaY,
In order to dynamically bind the property value you need to loop through each property and bind.
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Model
public class DashBoard
{
public List<Customer> Customers { get; set; }
public List<Order> Orders { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
NorthwindEntities entities = new NorthwindEntities();
DashBoard dashBoard = new DashBoard();
dashBoard.Customers = entities.Customers.Take(1).ToList();
dashBoard.Orders = entities.Orders.Take(1).ToList();
return View(dashBoard);
}
}
View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<_Dynamic_Property_Name.Models.DashBoard>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index</title>
</head>
<body>
<div>
<table>
<%foreach (var customer in Model.Customers)
{%>
<%foreach (var order in Model.Orders)
{%>
<tr>
<%foreach (System.ComponentModel.PropertyDescriptor prop in System.ComponentModel.TypeDescriptor.GetProperties(order))
{%>
<%if (prop.PropertyType.IsValueType || prop.PropertyType == typeof(string))
{%>
<%if (prop.Name != "EntityState")
{ %>
<th>
<%=prop.Name%>
</th>
<% } %>
<% } %>
<% } %>
</tr>
<%foreach (var item in customer.Orders)
{%>
<tr>
<%foreach (System.ComponentModel.PropertyDescriptor prop in System.ComponentModel.TypeDescriptor.GetProperties(item))
{%>
<%if (prop.PropertyType.IsValueType || prop.PropertyType == typeof(string))
{%>
<%if (prop.Name != "EntityState")
{ %>
<td>
<%=prop.GetValue(item)%>
</td>
<% } %>
<% } %>
<% } %>
</tr>
<% } %>
<% } %>
<% } %>
</table>
</div>
</body>
</html>
Screenshot
