Please tell me if I set this up wrong:
Model:
public List<double> Balance { get; set; } = new List<double>();
public List<double> MonthlyPrincipal { get; set; } = new List<double>();
public List<double> MonthlyInterest { get; set; } = new List<double>();
public List<double> AccumulativeInterest { get; set; } = new List<double>();
Controller:
for (int i = 0; i <= T; i++)
{
//math
double interest = balance * (R / 1200);
double principalPayment = monthlyPayment - interest;
double interestTotal = (balance + interest) - balance;
balance = balance - principalPayment;
cumulative = cumulative + interest;
//Pushing math to arrays.
balanceArray.Add(balance);
interestArray.Add(interestTotal);
principalpaymentArray.Add(principalPayment);
cumulativeArray.Add(cumulative);
}
model.MonthlyPrincipal = principalpaymentArray;
model.Balance = balanceArray;
model.MonthlyInterest = interestArray;
model.AccumulativeInterest = cumulativeArray;
View:
<tbody>
@for (var i = 1; i <= Model.Term; i++)
{
<tr>
<td>@i</td>
<td> @Html.DisplayFor(model => model.Payment)</td>
<td>@Html.DisplayFor(model => model.MonthlyPrincipal)</td>
<td>@Html.DisplayFor(model => model.MonthlyInterest)</td>
<td>@Html.DisplayFor(model => model.AccumulativeInterest)</td>
<td>@Html.DisplayFor(model => model.Balance)</td>
</tr>
}
</tbody>
Now what this is doing is printing every item in the array in the table columns. How do correct this?