Make sum of all queried data

1

I am making a report, I managed to get him to bring me the data of specific dates, but I am now needing him to bring me the sum of everything that was selected, I made an attempt but not the sum of everything, just a few things have been added.

My View:

Sales Report by Order / Period From: @ ViewBag.data Start to @ ViewBag.dataFinal                                                                                    

                <tr>

                    <th>N° Carro </th>
                    <th>Quant. </th>
                    <th>Km </th>
                    <th>Valor Unitário </th>
                    <th>Sub Total </th>
                    <th>Data Abastecimento </th>
                </tr>
                        @{foreach (var item in Model)
                            {
                                foreach(var iten in Model)
                                {
                             <tr>
                             <td> @Html.DisplayFor(modelItem => iten.NumCarro.NCarro) </td>
                             <td> @Html.DisplayFor(modelItem => iten.Litro) </td>
                             <td> @Html.DisplayFor(modelItem => iten.Km) </td>
                             <td> @Html.DisplayFor(modelItem => iten.VlrUnit) </td>
                             <td> @Html.DisplayFor(modelItem => iten.TotalGasto) </td>
                             <td> @Html.DisplayFor(modelItem => iten.DtAbastecido) </td>
                             </tr>
                            }
                                }
                        }

I'm not sure what to do,

Once the sum is returned:

    
asked by anonymous 21.12.2017 / 19:59

1 answer

1

The problem is in your loop that repeats the data. The sum is correct. Just remove the first foreach

@{

//Remover esse -> foreach (var item in Model) 

foreach(var iten in Model)
{
    <tr>
    <td> @Html.DisplayFor(modelItem => iten.NumCarro.NCarro) </td>
    <td> @Html.DisplayFor(modelItem => iten.Litro) </td>
    <td> @Html.DisplayFor(modelItem => iten.Km) </td>
    <td> @Html.DisplayFor(modelItem => iten.VlrUnit) </td>
    <td> @Html.DisplayFor(modelItem => iten.TotalGasto) </td>
    <td> @Html.DisplayFor(modelItem => iten.DtAbastecido) </td>
    </tr>
}

}
    
21.12.2017 / 20:28