1
I’m trying to use the concept of View Model Pattern, but when I’m implementing the compiler is showing a conversion error.
Below follows the approach I used:
Structure of the viewmodel
public class EvolucaoViewModel
{
public Chamado ChamadoAtual { get; set; }
public virtual ICollection<Evolucao> Evolucoes { get; set; }
}
Implementation in the controller
public ActionResult DetalharChamado(int? id)
{
EvolucaoViewModel model = new EvolucaoViewModel();
model.ChamadoAtual = _contexto.Chamados.Find(id);
model.Evolucoes = _contexto.Evolucoes.Where(e => e.id_chamado == id);
ViewBag.id_usuario = new SelectList(_contexto.Usuarios, "id_usuario", "nome_usuario", model.ChamadoAtual.id_usuario).OrderBy(p => p.Text);
ViewBag.id_chamado = id;
ViewBag.id_setor = new SelectList(_contexto.Setores, "id_setor", "nome_setor", model.ChamadoAtual.id_setor);
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
if (model == null)
{
return HttpNotFound();
}
return View(model);
}
When I try to do this assignment the VS presents me the message below:
model.Evolucoes = _contexto.Evolucoes.Where(e => e.id_chamado == id);
Error 3 Cannot implicitly Convert type 'System.Linq.Iqueryable' to 'System.Collections.Generic.Icollection'. An Explicit Conversion exists (are you Missing a cast?) E: Devspace Projetos Albasi.Atende Albasi.Atende.Web Controllers Chamadocontroller.Cs 77 31 Albasi.Atende.Web
What I need to modify?
It worked, young man?
– Jéf Bueno
Hello jbueno, for the controller yes, but for display in the view I only got through the Gridview helper. There is no way I can use Htmlhelper?
– Marcelo Almeida
Marcelo, great then. But I have no idea about this new problem. By the way, it should be solved in another publication, okay? Open a new question with your current question, explaining your scenario and mark the answer that helped you most as correct using the ✓ on the left side of the answer (you can only mark one as correct).
– Jéf Bueno