您好我是新來的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; }
我明白你想達到什麼,但什麼是你的題? –
我是否需要使用ItemOrderVM? –
我總是推薦使用viewModel。雖然它不是「必需」,但如果你想編寫好的代碼,這是必要的。 –