2017-05-09 3 views
0

L'élément de modèle passé dans le dictionnaire est de type « 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] '.élément de modèle passé dans le dictionnaire est de type « » mais disctionary a besoin d'un élément de modèle de type « »

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 Voir

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

Que Im essayant de faire est de remplir un tableau avec tous les Producten (produits) qui ont affecté un Voorraad (Stock) & Locatie (Lieu)

+0

Comme l'erreur dit: 'ToolsForEver_PVB.Models.VoorraadProductViewModel' n'est pas le même que le modèle qui s'attend à voir:' ToolsForEver_PVB.Models.ProductFabriekViewModel' - Vous devrez transformer vos éléments de modèle de données dans la bonne classe avant de les renvoyer à la vue? –

+0

Oh wow, que j'ai totalement raté celui-là ... mes excuses –

Répondre

0
@model IEnumerable<ToolsForEver_PVB.Models.ProductFabriekViewModel> 

EN

@model IEnumerable<ToolsForEver_PVB.Models.VoorraadProductViewModel>