I have this html:
<div class="row">
<div class="col-md-12">
@if (Model.PendingTransactions != null)
{
<table>
<thead>
<tr>
<th class="text-center">Select</th>
<th class="text-center">@Html.DisplayNameFor(m => m.PendingTransactions.First().transactionDate)</th>
<th class="text-center">@Html.DisplayNameFor(m => m.PendingTransactions.First().debtId)</th>
<th class="text-center">@Html.DisplayNameFor(m => m.PendingTransactions.First().batchId)</th>
<th class="text-center">Delete</th>
</tr>
</thead>
<tbody>
@foreach (var transaction in Model.PendingTransactions)
{
<tr id="row_@transaction.transactionBatchId">
<td>
@Html.CheckBoxFor(m => transaction.selectedForProcessing)
@Html.HiddenFor(m => transaction.selectedForProcessing)
</td>
<td class="text-center">@Html.DisplayFor(m => transaction.transactionDate)
@Html.HiddenFor(m => transaction.transactionDate)
</td>
<td class="text-center">
@Html.DisplayFor(m => transaction.debtId)
</td>
<td class="text-center">@Html.DisplayFor(m => transaction.transactionBatchId)</td>
<td><a onclick="deleteTransaction(@transaction.transactionBatchId)" href="#"><i class="bi bi-trash" aria-hidden="true"></i></a>
</td>
</tr>
}
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<input type="submit" class="btn btn-success float-right" />
</div>
</div>
}
</div>
</div>
For this model:
public class PendingTransactionsViewModel
{
public List<PendingTransactionViewModel> PendingTransactions { get; set; } = new();
}
public class PendingTransactionViewModel
{
public int? transactionBatchId { get; set; }
public int? debtId { get; set; }
public DateTime? transactionDate { get; set; }
public bool selectedForProcessing { get; set; } = false;
}
While I'm able to manipulate the checkbox on the view, when I postback the model property PendingTransactions
is not posting back to the controller. What am I missing in order to get the list back in the controller?