forum

Home / DeveloperSection / Forums / how to use a foreach in a view page

how to use a foreach in a view page

Anonymous User 1993 14-Aug-2014
Trying to pass a list of confirmed orders to the supplier 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);
}
//SupplierVM
public 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 Error Message: CS0012: The type 'IdeaBlade.EntityModel.Entity' is defined in an assembly that is not referenced. You must add a reference to assembly 'IdeaBlade.EntityModel, Version=6.1.7.0, Culture=neutral, PublicKeyToken=287b5094865421c0'.

Foreach loop for tables in MVC4 do I need to declare a variable for the list at the top and then run through that

any help appreciated. Thanks


c# c# 
Updated on 14-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By