使用MVC时遇到问题。
我创建了一个名为PO_Header的模型,该模型是采购订单标题,其他模型的名称为PO_Detail,即采购订单明细。
问题是我已经在Database,PO_Header和PO_Detail中创建了两个表但是我怎样才能为这两个表创建一个控制器和视图?
它们位于不同的表中,但我需要在同一个表单中添加它们,因此当我单击“创建/添加”时,两个表都将被更新。
PO_Header的模型:
[Table("PO_Header")]
public class PO_Header
{
[Key]
[DisplayName("Número Pedido")]
public string PONumber { get; set; }
[DisplayName("Cliente")]
public int CustomerID { get; set; }
[ForeignKey("CustomerID")]
public virtual Customers customers { get; set; }
[DisplayName("Expedidor")]
public string shipper { get; set; }
[DisplayName("RTA")]
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime rta { get; set; }
[DisplayName("Data de Envio")]
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime sendDate { get; set; }
[DisplayName("Data de Criação")]
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime createDate { get; set; }
[DisplayName("LI")]
public int LI_Number { get; set; }
}
PO_Detail的模型:
[Table("PO_Detail")]
public class PO_Detail
{
[DisplayName("Número Pedido")]
public string PONumber { get; set; }
[ForeignKey("PONumber")]
[Column(Order = 1)]
public virtual PO_Header poHeader { get; set; }
[Key]
[Column(Order = 2)]
[DisplayName("Part Number")]
public string partNumber { get; set; }
[Key]
[Column(Order = 3)]
[DisplayName("Line Number")]
public int lineNumber { get; set; }
[DisplayName("Fabricante")]
public int MakerID { get; set; }
[ForeignKey("MakerID")]
public virtual Makers makers { get; set; }
[DisplayName("Anuente")]
public bool anuente { get; set; }
[DisplayName("Quantidade")]
public int quantity { get; set; }
[DisplayName("Fornecedor")]
public int SupplierID { get; set; }
[ForeignKey("SupplierID")]
public virtual Suppliers suppliers { get; set; }
[DisplayName("Valor Unitário")]
public decimal? unitPrice { get; set; }
[DisplayName("Valor Total")]
public decimal? totalPrice { get; set; }
[DisplayName("Moeda")]
public int MoedaID { get; set; }
[ForeignKey("MoedaID")]
public virtual Sigla_Moeda siglaMoeda { get; set; }
}