I'm trying to show what my stored procedure brings and I want to send it to view:
This is how I sent it:
var Fechainicio = new SqlParameter
{
ParameterName = "inicio" ,
Value = FechaDesde
};
var FechaFinal = new SqlParameter
{
ParameterName = "final",
Value = FechaHasta
};
var empleadoid = new SqlParameter
{
ParameterName = "emp",
Value = 2393
};
var deduc = db.Database.SqlQuery<PlanillaController>("exec sp_DetalleDeduccionesEmpleado @inicio, @final, @emp", Fechainicio, FechaFinal, empleadoid).ToList<PlanillaController>();
ViewBag.deduc = deduc.ToList();
Already in the view it comes like this:
foreach (var Deduccionees in (IEnumerable<RecursosHumanos.Models.sp_DetalleDeduccionesEmpleado_Result>)ViewBag.Deduc)
{
<th>@Deduccionees</th>
}
This is the error
{"No se puede convertir un objeto de tipo 'System.Collections.Generic.List'1[RecursosHumanos.Controllers.PlanillaController]' al tipo 'System.Collections.Generic.IEnumerable'1[RecursosHumanos.Models.sp_DetalleDeduccionesEmpleado_Result]'."}
this is the data that the stored procedure should bring me
this is the sp:
create procedure sp_DetalleDeduccionesEmpleado @inicio datetime, @final datetime, @emp int
as
select
ded.DedId,
sum(ded.DetDedEmpValor),
emp.EmpId
from Tbl_DetalleDeduccionesEmpleado ded
inner join Tbl_Deducciones tip
on tip.DedId = ded.DedId
inner join Tbl_Empleado emp
on emp.EmpId = ded.EmpId
where ded.DetDedEmpFecha >= @inicio and
ded.DetDedEmpFecha <= @final and
ded.EmpId = @emp
group by ded.DedId, emp.EmpId