2
I own the ViewModel
down below:
public class Crm_AnaliseViewModel
{
public string TAG { get; set; }
public int ATUALIZACAO { get; set; }
public string RELATORIOS { get; set; }
}
Then in the Controler
done:
public async Task<ActionResult> Index(Crm_AnaliseViewModel model)
{
if (Session["cod_cli"] != null)
{
if(model == null)
{
model = new Crm_AnaliseViewModel();
}
int cod_cli = Convert.ToInt32(Session["cod_cli"]);
List<Crm_AnaliseViewModel> TAG_List = new List<Crm_AnaliseViewModel>();
var query = (from s in db.Crm_Analise
where s.cliente_CRM.Equals(cod_cli)
group s by s.TAG into g
select new
{
TG = g.Key,
AT = g.Max(t => t.data_creat),
RL = g.Count()
});
foreach(var item in query)
{
model.TAG = item.TG;
model.RELATORIOS = item.AT;
model.ATUALIZACAO = item.RL;
TAG_List.Add(model);
}
return View(TAG_List);
}
else
{
return RedirectToAction("Login", "Account");
}
}
It would be right to use List
to popular (if I may call it) a ViewModel
?
Your code doesn’t need to make a
foreach
can be summed up in another way! has no problem filling aforeach
the problem I’m seeing is in your code now!– novic