从数据库中获取数据后,如何在视图中显示三个模型中的数据?
我有错误:
invalidOperationException:模型项传递到 ViewDataDictionary是 类型为System.Collections.Generic.List1 [SalesTransactionApplication.Models.BLL.SalesTransactionInfo], 但是此ViewDataDictionary实例需要一个类型为 System.Collections.Generic.IEnumerable1 [SalesTransactionApplication.Models.BLL.Info.ViewModel]。
这是我的控制者:
public IActionResult Index()
{
SalesTransactionDataProvider objSalesTransactionProvider = new SalesTransactionDataProvider();
ViewData.Model=objSalesTransactionProvider.SalesTransactionGetList();
return View();
}
这是我的模特
public class CustomerInfo
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
public class ProductInfo
{
public int ProductId { get; set; }
[Required]
[Display(Name ="Product Name")]
public string ProductName { get; set; }
[Required]
[Range(0, float.MaxValue, ErrorMessage = "Please enter Numberic Value")]
[Display(Name = "Product Rate")]
public decimal ProductRate { get; set; }
}
public class SalesTransactionInfo
{
public int SalesTransactionId { get; set; }
[Required]
[Display(Name ="Customer ID")]
public int CustomerId { get; set; }
[Required]
[Display(Name = "Product ID")]
public int ProductId { get; set; }
[Required]
public float Quantity { get; set; }
[Required]
public decimal Rate { get; set; }
[Required]
public decimal Total { get; set; }
public int InvoiceId { get; set; }
}