I am trying to sum 2 columns in my grade-view, which contains Debit
and RemaininAmount
, but it only gives me one result for one column. How can I sum for the second column?
This is my view :
<td>
@Html.DisplayFor(modelItem => item.Debit)
</td>
<td>
@{
var RemaininAmount = item.contracts.AmountOfRent - item.Debit;
}
@RemaininAmount
</td>
</tbody> }
<td>Total</td>
<td>@Model.Sum(x => x.Debit)</td>
<td>@Model.Sum(s => s.RemaininAmount)</td>
This is my output:
It looks like you're simply displaying different values in the data cells vs the total. You're displaying item.contracts.AmountOfRent - item.Debit
but you are summing s.RemaininAmount
. Maybe try:
@Model.Sum(s => s.contracts.AmountOfRent - s.Debit)
so that you sum the value you are displaying.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.