I wanted to get invoice items from the database,But there's a problem in IEnumerable Type
Error
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.InvoiceHD_19624A0A21E23E6589B4A75F4B214A34A6186F3A2FF588A6B9CC2A40272A9BBD', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ICSNew.Data.InvoiceHD]'.
My Controller
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);
}
My View
@model IEnumerable<ICSNew.Data.InvoiceHD>
@{
Layout = null;
}
<h2>GetInvoice</h2>
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.CashAmount)
}
My Repository
public InvoiceHD GetInvoiceItemByInvoiceId(int InvoiceId)
{
try
{
return context.InvoiceHDs.Where(x => x.InvoiceId == InvoiceId
&& x.IsActive == true).FirstOrDefault();
}
catch (Exception ex)
{
return new InvoiceHD();
}
}