0

The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery1[ToolsForEver_PVB.Models.VoorraadProductViewModel]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[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);

Catalogus View

@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>

What im trying to do is Fill a Table with all the Producten(Products) that have assigned a Voorraad(Stock) & Locatie(Location)

  • As the error says: `ToolsForEver_PVB.Models.VoorraadProductViewModel` is not the same as the model that view is expecting: `ToolsForEver_PVB.Models.ProductFabriekViewModel`- You'll need to transform your data model items to the right class before return them to the view? – Karel Tamayo May 09 '17 at 18:54
  • Oh wow, that i have totally missed that one... my apologies – Leroy Beukers May 09 '17 at 19:03

1 Answers1

0
@model IEnumerable<ToolsForEver_PVB.Models.ProductFabriekViewModel>

INTO

@model IEnumerable<ToolsForEver_PVB.Models.VoorraadProductViewModel>