My foreach
loops through a List, and I need the loop to write itself to a text file in a form like this:
[
{
"Platillo": "Pozole",
"PDV": "Restaurante",
"Turno": "matutino",
"PV": "$45.00",
"1": "1",
"2": "1"
},]
My foreach loop fills a html table at the moment.
foreach (var item in Model)
{
var total = 0;
decimal costo = 0;
for (int i = 1; i <= 31; i++)
{
var value = 0;
if (item.Fecha.Day == i) { value = item.Cantidad; costo = costo + item.Total; }
total += value;
}
<tr>
<td class="descripcion">@item.Descripcion</td>
<td class="pdv">@item.Pdv</td>
<td class="pdv">@item.Rid</td>
<td>@((costo / (total + 1)).ToString("C"))</td>
@for (int i = 1; i <= 31; i++)
{
var value = 0;
int month = item.Fecha.Month;
if (item.Fecha.Day == i) { value = item.Cantidad; }
}
<td>@total</td>
<td>@(((costo / (total + 1)) * total).ToString("C"))</td>
How do I do this in columns, and do that for every item in my foreach
statement?