I’m new in using MVC and I have a question about summarizing the row data in a table.
Some background:
First I collect a lot of data with an ordinary SQL statement. I use a DataTable to store the data. Then I output the data with an ordinary HTML table. This works very nicely and I have no problems with it.
I would now like to summarize all of the values for each row and display the result in the bottom row.
I know that I could do this already in the data layer. Loop through the datatable and summarize the values for the rows into a new row. Then finally append the “summary row” as the last row.
Some code:
<tr class="header">
<th>Person</th>
<th>NrOfRows</th>
</tr>
<% foreach (System.Data.DataRow row in Model.Rows) { %>
<tr>
<td><%: row["Name"].ToString()%></td>
<td><%: row["NrOfRows"].ToString()%></td>
</tr>
Could you please advice me which would be the best/easiest way to do this
Do the calculation in the ControllerAction. something like this…