传递到字典中的模型项的类型为'System.Data.Entity.Infrastructure.DbQuery
1[ToolsForEver_PVB.Models.VoorraadProductViewModel]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [ToolsForEver_PVB.Models.ProductFabriekViewModel]'。
VoorraadProductViewModel
public class VoorraadProductViewModel
{
public Voorraad Voorraad { get; set; }
public Product Product { get; set; }
public Locatie Locatie { get; set; }
}
VooraadController
public ActionResult Catalogus()
{
ApplicationDbContext db = new ApplicationDbContext();
var result = from vd in db.Voorraads
join pd in db.Products on vd.ProductId equals pd.Id
join ld in db.Locaties on vd.LocatieId equals ld.Id
where ld.Id != null
select new VoorraadProductViewModel() { Voorraad = vd,Product = pd, Locatie = ld };
return View(result);
目录视图
@model IEnumerable<ToolsForEver_PVB.Models.ProductFabriekViewModel>
@{
ViewBag.Title = "Catalogus";
}
<h2>Catalogus</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
@Html.DisplayFor(modelitem => item.Product.Naam) - @Html.DisplayFor(modelItem => item.Product.Type)
</h3>
</div>
</div>
</td>
</tr>
}
</table>
我想要做的是填写一张表格,其中包含已分配了Voorraad(Stock)&amp;的所有Producten(产品)。 Locatie(位置)
答案 0 :(得分:0)
@model IEnumerable<ToolsForEver_PVB.Models.ProductFabriekViewModel>
INTO
@model IEnumerable<ToolsForEver_PVB.Models.VoorraadProductViewModel>