Tengo un checkbox donde envio los datos al controller para hacer la consulta en linq donde quiero hacer un having pero no lo puedo lograr obtener, me envia la lista con 0 y otros valores, quiero solo que aparezca cuando sea > 0.
Asi mismo cuando quiero agregar otros datos al select me indica que fc no esta dento del contexto,
mi query es este:
select c_prestamo, d_preanexo , c_factura , sum(n_cximp) as Suma
from t_cxc
group by c_factura, c_prestamo, d_preanexo
having sum(n_cximp) <> 0
Controlador:
[HttpPost]
public ActionResult ViewFact(List<LstReportes> model)
{
foreach (LstReportes item in model)
{
if (item.isChecked == true)
{
var fact2 = (from fc in db.t_cxc
where fc.c_cliente == item.c_cliente && fc.c_prestamo == item.c_prestamo
&& fc.c_tipocontrato == item.c_tipocontrato && fc.d_preanexo == item.d_preanexo
group fc by new { fc.c_factura, fc.c_prestamo, fc.d_preanexo } into g
select new LstReportes
{
c_prestamo = fc.c_prestamo,
n_cximp = g.Sum(x => x.n_cximp) > 0
}).ToList();
ViewBag.model = fact2;
}
else if (item.isChecked == false)
{
}
}
return View();
}
Vista:
<tbody>
@foreach (var item in (IEnumerable<ArrendamientoWeb.Models.LstReportes>)ViewBag.model)
{
<tr>
<td>
@item.c_factura
</td>
<td>
@item.f_cxfecven
</td>
<td>
@item.n_cximp
</td>
</tr>
}
</tbody>
¿Qué estoy haciendo mal?
ViewBag.model = fact2.Where(x=> x.n_cximp>0)
. Prueba a ver si te vale asi...foreach
? porque en cada iteracion pisas el dato anterior del ViewBag. En la consulta sql que usaste de base no veo ningun where