use foreach in a mvc view

0
  

In the ViewBag.Deducciones : bring me the deductions you selected previously.

     

In the ViewBag.DeducesEmployees : it brings me the deductions that the employee has selected ().

The problem is that for every deduction I go through all the deductions assigned to the employees, how else could I order that.

@foreach (var item in Model)
            {

                <tr>
                    <td>@item.EmpId</td>
                    @*<td>@item.EmpNombre @item.EmpApellido</td>*@
                    <td><p style="white-space: nowrap;">@item.EmpNombre @item.EmpApellido</p></td> 
                    <td>@item.PueDescripcion</td>
                    @*<td>@item.sueldo</td>*@
                    <td> @String.Format("{0:C}", item.sueldo) </td>
                    <td>@item.Ihss</td>
                    <td>@item.rap</td>



                    @*Deducciones Empleado*@
                    @if (ViewBag.DeduccionesEmpleados != null)
                    {

                        foreach (var Deduccion in (List<string>)ViewBag.Deducciones)
                        {
                            foreach (var Deduccionees in (IEnumerable<RecursosHumanos.Models.Con_DetalleDeduccionesEmpleado>)ViewBag.DeduccionesEmpleados)
                            {

                                if (Deduccionees.EmpId == item.EmpId)
                                {
                                    if (Deduccionees.DedDescripcion == Deduccion)
                                    {
                                        <th>@Deduccionees.DetDedEmpValor</th>

                                        break;


                                    }

                                    else
                                    {
                                        <th> </th>
                                    }
                                }

                            }

                        }

                    }
    
asked by Marco Eufragio 17.10.2018 в 22:19
source

1 answer

1

I recommend that before returning two viewbags, make a viewbag where you remove the matches, so you do not have to do double foreach in the view.

    
answered by 07.11.2018 / 21:19
source