I'm trying to perform the query below:
var query = from s in db.Crm_Analise
where s.cliente_CRM == cod_cli
group s by s.TAG into g
select new
{
TAG = g.Key,
ATUALIZAÇÃO = g.Max(t => t.data_creat),
RELATÓRIOS = g.Count(t => t.modelo != null)
};
However, the error is displayed:
FollowView
:
@modelIEnumerable<OneeWeb_v3.Models.Crm_Analise>@{ViewBag.title="TAG's";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h2>@ViewBag.title</h2>
<table class="table">
<tr>
<th>
@Html.ActionLink("TAG", "Index")
</th>
<th>
@Html.ActionLink("ATUALIZAÇÃO", "Index")
</th>
<th>
@Html.ActionLink("RELATÓRIOS", "Index")
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TAG)
</td>
<td>
@Html.DisplayFor(modelItem => item.data_creat)
</td>
<td>
@Html.DisplayFor(modelItem => item.modelo)
</td>
<td>
@Html.ActionLink("Visualizar", "Details")
</td>
</tr>
}
</table>
<ul class="pager">
<li><a href="#">Anterior</a></li>
<li><a href="#">Proximo</a></li>
</ul>
Model:
public class Crm_Analise
{
[Key]
public int id { get; set; }
public string cod_item_CRM { get; set; }
public string TAG { get; set; }
public string data_creat { get; set; }
public string modelo { get; set; }
public int cliente_CRM { get; set; }
}
Controller:
// GET: Crm_Analise
[Authorize]
public async Task<ActionResult> Index()
{
if (Session["cod_cli"] != null)
{
int cod_cli = Convert.ToInt32(Session["cod_cli"]);
var query = from s in db.Crm_Analise
where s.cliente_CRM == cod_cli
select new
{
TAG = s.TAG,
ATUALIZAÇÃO = s.data_creat,
RELATÓRIOS = s.cod_item_CRM
};
if (query.Count() > 0)
{
return View(await query.ToListAsync());
}
else
{
return RedirectToAction("Index", "Home", new { cod_cli = Session["cod_cli"], razao_social = Session["razao_social"] });
}
}
else
{
return RedirectToAction("Login", "Account");
}
}
I know that there is something with @model IEnumerable<OneeWeb_v3.Models.Crm_Analise>
but I do not know how to solve it.