I need to know how I can export the next table I have in a project view to an excel document.
The table I want to export to excel is as follows:
<table class="exampletb table table-bordered table-hover display">
<thead>
<tr>
<th>Colaborador</th>
<th>Lider</th>
<th>Eje</th>
</tr>
</thead>
<tbody>
@foreach (var item in ViewBag.colaboradores)
{
var namelider = item.lider;
var codigo_col = item.codigo;
var lider = (from p in ((List<SI_OldMutual.Models.Collaborators>)ViewBag.email_lider).Where(n => n.nombres == namelider)
select p.email).ToList();
if (lider.Count == 0)
{
ViewBag.test = "No existe";
}
else
{
ViewBag.test = lider[0];
}
<tr>
<td>@item.nombres</td>
<td>@item.lider</td>
<td>@item.eje_funcional</td>
@foreach (var peso in ((List<SI_OldMutual.Models.Objectives>)ViewBag.pesos).Where(n => n.Lider == ViewBag.test))
{
<td>@peso.Peso_Objetivo</td>
}
@foreach (var calificacion in ((List<SI_OldMutual.Models.CalificarColaborador>)ViewBag.calificaciones).Where(n => n.codigo_colaborador == codigo_col))
{
<td>@calificacion.calificacion</td>
}
</tr>
}
</tbody>
</table>
They tell me that I can do it from the controller but I have no idea how to do it, I'm new to this Asp.Net Mvc5. My idea is to make it export that table with the same logic that I'm using in view.
My controller is this:
public ActionResult Index()
{
ViewBag.colaboradores = (from p in db.Collaborators
where p.grupo_lider == "NO"
select p).ToList();
ViewBag.pesos = (from p in db.Objectives
select p).ToList();
ViewBag.calificaciones = (from p in db.CalificarColaboradors
select p).ToList();
ViewBag.email_lider = (from p in db.Collaborators where p.grupo_lider == "SI"
select p).ToList();
return View();
}
It should be noted that the table is painted in the view as follows since the results of the weights and grades may vary depending on the person and are not always the same amount, I leave an image to understand a little better :
This is why I need to be able to export this table as it is painted in the view or at least using the same logic.
In case of doubt my namespace
is SI_OldMutual