Stored procedure: CREATE PROCEDURE [dbo].[getCustomer] AS BEGIN SELECT TOP 10 CustomerID, CustomerName, City FROM Customers END --------------------------------------- CREATE PROCEDURE [dbo].[getOrder] @CustomerID nchar(5) AS SELECT OrderID, OrderDate, RequiredDate, ShippedDate FROM Orders WHERE CustomerID = @CustomerID ORDER BY OrderID ------------------------------------------------ Controller Code: using (IDbConnection conn = new SqlConnection(@"xxx)) { List result = new List(); var customers = conn.Query("getCustomer",commandType: CommandType.StoredProcedure); foreach (Customer customer in customers.ToList()) { DynamicParameters paramView = new DynamicParameters(); paramView.Add("@CustomerID", customer.CustomerId, DbType.Int32, ParameterDirection.Input); var orders = conn.Query("getOrder",paramView,commandType: CommandType.StoredProcedure); result.Add(new CustomerModel { Customer=customer, Orders=orders.ToList() }); } //result.Customers return View(result); } ----------------------------------------------------- View Code: @{ WebGrid webGrid = new WebGrid(source: Model, canSort: false, canPage: false); } @webGrid.GetHtml( htmlAttributes: new { @id = "WebGrid", @class = "Grid" }, columns: webGrid.Columns( webGrid.Column(null, null, format: @
), webGrid.Column("Customer.CustomerName", "Customer Name"), webGrid.Column("Customer.City", "City"), webGrid.Column(format: (item) => { WebGrid childGrid = new WebGrid(source: item.Orders, canSort: false, canPage: false); return childGrid.GetHtml( htmlAttributes: new { @class = "ChildGrid" }, columns: childGrid.Columns( childGrid.Column("OrderId", "OrderId"), childGrid.Column("OrderDate", "OrderDate"), childGrid.Column("RequiredDate", "RequiredDate"), childGrid.Column("ShippedDate", "ShippedDate") ) ); }) ) );