I'm developing an ASP.NET MVC project, with DDD structure and using Simple Injector. I can perform persistence in BD normally, but at the moment of retrieving the information and displaying it in a list, it presents the following error message.
The template item entered in the dictionary is from type 'System.Collections.Generic.List
1[Domain.Entities.SistemaEntities]', mas esse dicionário requer um item do tipo 'System.Collections.Generic.IEnumerable
1 [View.Models.SystemViewModel]'.
This is the control that is calling the method for searching the information:
public ActionResult Index()
{
var resultado = _SistemaDominio.GetAll().AsEnumerable();
return View(resultado);
}
And this is the page that lists.
@model IEnumerable<View.Models.SistemaViewModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Insert")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.CodSistema)
</th>
<th>
@Html.DisplayNameFor(model => model.Nome)
</th>
<th>
@Html.DisplayNameFor(model => model.Descricao)
</th>
<th>
@Html.DisplayNameFor(model => model.DTCadastro)
</th>
<th>
@Html.DisplayNameFor(model => model.Status)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.CodSistema)
</td>
<td>
@Html.DisplayFor(modelItem => item.Nome)
</td>
<td>
@Html.DisplayFor(modelItem => item.Descricao)
</td>
<td>
@Html.DisplayFor(modelItem => item.DTCadastro)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.ActionLink("Edit", "Update", new { id=item.IDSistema }) |
@Html.ActionLink("Details", "Details", new { id=item.IDSistema }) |
@Html.ActionLink("Delete", "Delete", new { id=item.IDSistema })
</td>
</tr>
}
</table>
Domain.Service class
public IList<SistemaEntities> GetAll()
{
var resultado = _repositorioSistema.GetAll();
return resultado;
}
Data.Repositories class
public IList<TEntities> GetAll()
{
return _context.Set<TEntities>().ToList();
}
I can not pass the Entity data to the ViewModel in any way.