【发布时间】:2014-09-28 15:57:25
【问题描述】:
我想从数据库中获取发票项目,但是IEnumerable Type有问题
错误
传入字典的模型项的类型为“System.Data.Entity.DynamicProxies.InvoiceHD_19624A0A21E23E6589B4A75F4B214A34A6186F3A2FF588A6B9CC2A40272A9BBD”,但此字典需要“System.Collections.Generic.IEnumerable`1[ICSNew.Data.InvoiceHD] 类型的模型项
我的控制器
public ActionResult GetInvoice(int Id)
{
Models.InvoiceHDViewModel _invHd = new Models.InvoiceHDViewModel();
ICSNew.Data.InvoiceHD _invOdr = new Data.InvoiceHD();
_invOdr = (new ICSNew.Business.ICSNewController.SalesController())
.GetInvoiceItemByInvoiceId(Id);
_invHd.Cash = _invOdr.CashAmount;
return View(_invOdr);
}
我的观点
@model IEnumerable<ICSNew.Data.InvoiceHD>
@{
Layout = null;
}
<h2>GetInvoice</h2>
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.CashAmount)
}
我的仓库
public InvoiceHD GetInvoiceItemByInvoiceId(int InvoiceId)
{
try
{
return context.InvoiceHDs.Where(x => x.InvoiceId == InvoiceId
&& x.IsActive == true).FirstOrDefault();
}
catch (Exception ex)
{
return new InvoiceHD();
}
}
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4