我對C#很陌生,仍然在學習,如果這是一個簡單的問題,我很抱歉。 當用戶訂購一個或多個項目時,將爲這些項目分配一個OrderId,然後使用此OrderId將其與訂單相關聯。現在,但是我需要鏈接這兩個並顯示它們,因此只有訂購它們的用戶才能查看它們(基於存儲在訂單類中的用戶名)C#訂單清單
我會如何在ViewOrdersController中執行此操作?
當前職業: 訂購
[Bind(Exclude = "OrderId")]
public partial class Order
{
[ScaffoldColumn(false)]
public int OrderId { get; set; }
[ScaffoldColumn(false)]
public System.DateTime OrderDate { get; set; }
[ScaffoldColumn(false)]
[Remote("CheckUserName", "Account")]
public string Username { get; set; }
[Required]
[StringLength(16, ErrorMessage = "Your name is too long")]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Your last name is required.")]
[StringLength(16, ErrorMessage = "Last name is too long.")]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required(ErrorMessage = "Address is required.")]
public string Address { get; set; }
[Required(ErrorMessage = "City is required.")]
public string City { get; set; }
[Required(ErrorMessage = "Postcode is required.")]
[Display(Name = "Post Code")]
public string PostalCode { get; set; }
[Required(ErrorMessage = "Country is required.")]
public string Country { get; set; }
[Required(ErrorMessage = "Phone number is required.")]
public string Phone { get; set; }
[RegularExpression(@"[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}", ErrorMessage = "Email doesn't look like a valid email address.")]
public string Email { get; set; }
[System.ComponentModel.DataAnnotations.Compare("Email")]
[Display(Name = "Confirm your email address")]
public string EmailConfirm { get; set; }
[ScaffoldColumn(false)]
public string PaymentTransactionId { get; set; }
public bool HasBeenShipped { get; set; }
[ScaffoldColumn(false)]
[ReadOnly(true)]
public decimal Total { get; set; }
public List<OrderDetail> OrderDetails { get; set; }
}
的OrderDetail
public class OrderDetail
{
public int OrderDetailId { get; set; }
public int OrderId { get; set; }
public int ProductId { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public virtual Product Product { get; set; }
public virtual Order Order { get; set; }
}
我試着去創建一個控制器,允許對已作出的命令來查看自己的訂單的用戶
你的問題完全含糊 - 你可以顯示你當前的課程嗎? 另外,這是什麼ViewOrdersController?列表顯示項目?定製控制器? – ArielB
顯示你已經嘗試過的一些代碼? –
對不起回覆我意識到它是多麼模糊,在一瞬間編輯不了主要的帖子 –