Sum in a razor view with ASP.NET

Viewed 63

What I want to do is a sum between two Models(razor ASP.NET). (they are created in the database) I don't want to do it in the controller, because later I want it not to modify my value. I need to do it in the view one way or another, either by taking out the forEach. Thank you very much I hope your help.

<div class="cuartaParte">
        <table style="width: 100%">
          @foreach (var item in Model.PresupuestoDetalle){
          <tr> //here I want to do the sum
            <th scope="row" style="width: 70%; text-align: right">Descuento @Model.Cliente.Descuento+=@Model.DescuentoExtraPorcen%</th>
            <td>$@Model.ImporteDescuento</td>
          </tr>
          }
        </table>
      </div>
1 Answers

If you want to show the sum between two Models in the view,try to use @() outside Model.Cliente.Descuento and Model.DescuentoExtraPorcen%;

<div class="cuartaParte">
        <table style="width: 100%">
          @foreach (var item in Model.PresupuestoDetalle){
          <tr> //here I want to do the sum
            <th scope="row" style="width: 70%; text-align: right">Descuento @(Model.Cliente.Descuento+@Model.DescuentoExtraPorcen%)</th>
            <td>$@Model.ImporteDescuento</td>
          </tr>
          }
        </table>
      </div>
Related