je suis tryng pour afficher la liste de mes clients à mon avis je suis arrivé cette erreurpassé dans le dictionnaire est de type « System.Collections.Generic.List`but ce dictionnaire requires'System.Collections.Generic.IEnumerable`
l'élément de modèle passé dans le dictionnaire est de type « System.Collections.Generic.List
1[PDF.View_model.Customers]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
dans remplir ma liste dans la couche de modèle et de le transmettre pdf.view_model.View_model jeter ce qui est
public IEnumerable<Customers> GetAllCustomers(int? _id)
{
Ref_customers = new List<Customers>();
CList = new List<Models.EF_Model.Customer>();
foreach (var item in CList)
{
Ref_customers.Add(new Customers() { id = item.Id, FName = item.FName, LName = item.LName, Paid = item.Paid });
}
return Ref_customers;
et dans mon modèle
` public List<EF_Model.Customer> GetAllCustmers(int? _id)
{
using (var Context = new EF_Model.CoolerEntities())
{
return (_id.HasValue ? Context.Customers.Where(p => p.Id == _id).ToList() : Context.Customers.ToList());
}
}`
et enfin dans mon contrôleur
`
public ActionResult Index(int? id)
{
Ref_ViewModel = new View_model.View_Model();
return View(Ref_ViewModel.GetAllCustomers(id));
}
`
et à mon avis, j'ai posté une petite quantité de celui-ci, il affiche une liste des clients la fin par une déclaration de foreach
`
@model IEnumerable<PDF.View_model.Customers>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FName)
</th>
<th>
@Html.DisplayNameFor(model => model.LName)
</th>
<th>
@Html.DisplayNameFor(model => model.Paid)
</th>
<th>
@Html.DisplayNameFor(model => model.Password)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Paid)
</td>
<td>
@Html.DisplayFor(modelItem => item.Password)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
model.custom er est tout simplement un DTO de ma table j'ai aussi dans mon view_model.Customer
Comment convertir liste IEnumerable? Je sais que la liste est IEnumrable ne sais pas quoi faire
je suis confus
La dernière partie du message d'erreur est manquante - _... de type 'System.Collections.Generic.IEnumerable _ –
@StephenMuecke IEnumerable 1 [PDF.Models.EF_Model.Customer]'. –
Vous avez 2 classes Customer, PDF.View_model.Customers et PDF.Models.EF_Model.Customer? – sachin