2015-09-08 150 views
3

您好我是新來的MVC,我想添加一個功能到我的程序,我有客戶詳細信息,並與他們已經把過去的訂單頁面。但在頁面上,它還必須顯示屬於該訂單的訂單商品,例如他們在亞馬遜上的操作方式。如何顯示的客戶訂單記錄與訂單項目

我的客戶詳細信息查看

 <header class="panel-heading"> 
      Customer Details 
     </header> 
     <div class="panel-body"> 
      <dl class="dl-horizontal"> 
       <dt style=" font-size: large; float:left"> 
        Name: 
       </dt> 

       <dd style="font-size:large;margin-left:15px; float:left"> 
        @Html.DisplayFor(model => model.customer_name) 
        @Html.DisplayFor(model => model.customer_surname) 
       </dd> 



       <dt style=" font-size: large; float:left"> 
        Cellphone: 

       </dt> 

       <dd style="font-size:large;margin-left:15px; float:left"> 
        @Html.DisplayFor(model => model.customer_cell) 

       </dd> 

       <dt style=" font-size: large; float:left"> 
        Email: 

       </dt> 

       <dd style="font-size:large;margin-left:15px; float:left"> 
        @Html.DisplayFor(model => model.customer_email) 

       </dd> 

       <dt style=" font-size: large; float:left"> 
        Address: 

       </dt> 

       <dd style="font-size:large;margin-left:15px; float:left"> 
        @Html.DisplayFor(model => model.customer_addressline1)<br /> 
        @Html.DisplayFor(model => model.customer_addressline2)<br /> 
        @Html.DisplayFor(model => model.customer_addressline3) 
       </dd> 

       <dt style=" font-size: large; float:left"> 
        Join Date: 

       </dt> 

       <dd style="font-size:large;margin-left:15px; float:left"> 
        @Html.DisplayFor(model => model.customer_join_date) 

       </dd> 


      </dl> 
     </div> 
     </section> 
    </div> 

訂貨型號

public class ORDER 
    { 
     [DisplayName("Order ID")] 
       public int OrderID { get; set; } 
     [DisplayName("Customer ID")] 
     public int CustomerID { get; set; } 
     [DisplayName("Batch ID")] 
     public Nullable<int> DeliveryID { get; set; } 
     [DisplayName("Employee ID")] 
     public int EmployeeID { get; set; } 
     [DisplayName("Date")] 
     [DataType(DataType.Date)] 
     [DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}", ApplyFormatInEditMode = true)] 
     public System.DateTime order_date { get; set; } 
     [DisplayName("Time")] 
[DataType(DataType.Time)] 
     [DisplayFormat(DataFormatString="{0:H:mm}",ApplyFormatInEditMode=true)] 
     public System.DateTime order_time { get; set; } 
     [DisplayName("Status")] 
     public String order_status { get; set; } 
     [DisplayName("Preferred Date")] 
     [DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}", ApplyFormatInEditMode = true)] 
     public System.DateTime order_preffered_date { get; set; } 


     public virtual DELIVERY DELIVERY { get; set; } 
     public virtual CUSTOMER CUSTOMER { get; set; } 
     public virtual EMPLOYEE EMPLOYEE { get; set; } 
     public virtual ICollection<ITEM_ORDER> ITEM_ORDER { get; set; } 

    } 

我Item_Order型號

public class ITEM_ORDER 
    { 

     public int Item_OrderID { get; set; } 
     public int ItemID { get; set; } 
     public int OrderID { get; set; } 
     [DisplayName("Quantity")] 
     [Range(1, int.MaxValue, ErrorMessage = "Quantity must be greater than 0")] 
     public int item_order_quantity { get; set; } 

     public virtual ITEM ITEM { get; set; } 
     public virtual ORDER ORDER { get; set; } 
    } 

Item_Order VM

public int? ID { get; set; } 
public int OrderID { get; set; } 
public int CustomerID { get; set; } 
public int ItemID { get; set; } 
[DisplayName("Quantity")] 
[Range(1, int.MaxValue, ErrorMessage = "Quantity must be greater than 0")] 
public int item_order_quantity { get; set; } 
[Display(Name = "Brand")] 
public int ? SelectedBrand { get; set; } 
[Display(Name = "Description")] 
public int SelectedItem { get; set; } 
public SelectList BrandList { get; set; } 
public SelectList ItemList { get; set; } 
public List<OrderVM> Orders { get; set; } 
+0

我明白你想達到什麼,但什麼是你的題? –

+0

我是否需要使用ItemOrderVM? –

+0

我總是推薦使用viewModel。雖然它不是「必需」,但如果你想編寫好的代碼,這是必要的。 –

回答

0

你想展示項目的列表,所以你需要通過他們迭代,這樣的事情:

<table id="orderTable"> 
    @foreach (var order in Model.Orders) 
    { 
     <tr> 
      <td>@order.date</td> 
      <td>@order.id</td> 
      <td>@order.customerName</td> 
     </tr> 
    } 
</table> 

@丹蟠龍:這是解決提問者的問題,因爲他要求(以評論)如何在ordersList顯示的項目,那就是我的思考方式......反正我延長了答案,但我不能提供的信息做更多的

+0

請添加一個解釋如何解決askers問題。 [答案] –

+0

您好我想顯示類似上面的命令,但我也必須看到的物品從Item_Order模型 –

+0

這樣才能內購買(由OrderVM的結構因),你將不得不作出一個嵌套循環或者你可以用ajax調用一個master-detail結構來填充OrderDetails表格,當點擊Order的行時。這將取決於你想要的設計和UX –