1
The query data is correct, but I cannot return the data to the view.
Controller:
var disponib = (from d in db.Disponibilidade
join c in db.Catequista on d.CatequistaID equals c.CatequistaID
where c.CatequistaID == d.CatequistaID && d.CatequistaID == id
select new
{
AnoPastoral = d.AnoPastoral,
DiaDisponivel = d.DiaDisponivel,
HoraDisponivel = d.HoraDisponivel,
HoraFim = d.HoraFim,
Observacoes = d.Observacoes,
}).ToList();
ViewBag.Disponibilidade = disponib;
View:
@model WebAppCatechesis2.Models.Catequista
@foreach (var item in ViewBag.Disponibilidade)
{
// ???
}
Ever tried to give a
cast
in Viewbag? Something like:ViewBag.Disponibilidade as ICollection<SUACLASSE>
?– Marllon Nasser
@Marllonnasser the foreach already cast .
– Marco Souza
Some solution?
– WickedOne
Can’t you create a Viewmodel class that contains a class with a list of availabilities? This would make the development flow "more correct". Viewbag may not be the best option.
– Thiago Silva