---
title: "how to use a foreach in a view page"  
description: "how to use a foreach in a view page"  
author: "Anonymous User"  
published: 2014-08-14  
updated: 2014-08-14  
canonical: https://www.mindstick.com/forum/2034/how-to-use-a-foreach-in-a-view-page  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# how to use a foreach in a view page

Trying to pass a list of confirmed orders to the [supplier](https://www.mindstick.com/news/2885/apple-supplier-foxconn-wins-airpod-deal-and-launches-200-million-factory-in-india) page (checked with breakpoint the list is being past) just having problems using a foreach to display the list in the view.

```
//SupplierController  public ActionResult Index() { BuyABicycle_Entities db1 = new BuyABicycle_Entities(); IEnumerable<BicycleOrder> All_Orders = (from c in db1.BicycleOrders                                                    where c.Id >= 1                                                    select c).ToList();  SupplierVM model = new SupplierVM { allOrders = All_Orders };  return View(model);}//SupplierVMpublic class SupplierVM{  public IEnumerable<BicycleOrder> allOrders { get; set; }}Views/Supplier/Index@model BicycleShop.ViewModels.SupplierVM    @{        ViewBag.Title = "Supplier";        //var orders = (IList<BicycleOrder>) Model.;        // var orders = (List<BicycleOrder>) Model.Order);    }    @using (Html.BeginForm())    {    <table>        @foreach (var _Order in Model.allOrders)         {           <text>               <tr>                  <td>@_Order.CustomerName</td>                     </tr>            </text>}    </table>    <input type="submit" />}
```

This throws the error with @foreach (var _Order in Model.allOrders) [Compiler](https://www.mindstick.com/articles/27/just-in-time-compiler) [Error Message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration): CS0012: The type 'IdeaBlade.EntityModel.Entity' is defined in an [assembly](https://www.mindstick.com/articles/25/global-assembly-cache) that is not referenced. You must add a [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) to assembly 'IdeaBlade.EntityModel, [Version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version)=6.1.7.0, [Culture](https://www.mindstick.com/articles/44200/5-ways-to-improve-the-company-culture)=neutral, PublicKeyToken=287b5094865421c0'.

[Foreach loop](https://www.mindstick.com/forum/182/problem-in-getting-the-value-from-array-by-using-foreach-loop) for tables in MVC4 do I need to declare a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) for the list at the top and then run through that

any help appreciated. Thanks

## Replies

### Reply by Pravesh Singh

Hi Jay,You can try this:

```
@foreach (var _Order in Model)    {        <text>        <tr>           
<td>@Html.TextBoxFor(x => x.allOrders)</td>           
<td>@_Order.allOrders</td>           
@<td>@Html.TextBoxFor(x => x.CustomerName, new { @readonly =true }) </td>           
@foreach(var item in _Order)             {                 item.ItemProp
<br />             }        </tr>        </text>    }
```


---

Original Source: https://www.mindstick.com/forum/2034/how-to-use-a-foreach-in-a-view-page

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
