I have a standard Razor Page that lists all Orders in my database. It's coded pretty standard: IList<Order>
bind property in page model, OnPost method. However, each of the records in a table has a column with a select element that shows the current status of the order, and a button to save the new status if the user decides to change it. Sort of an inline edit of the status for each row.
So I have a foreach loop in my page that cycles through all my orders:
@foreach (var item in Model.Orders)
{
<tr><td>...</td></tr>
<tr>
<td>
<form method="post" class="form-inline">
<input type="hidden" value="@item.Id"/>
<select asp-for="@item.OrderStatusId"
class="form-control form-control-sm"
asp-items="ViewBag.OrderStatusId"></select>
<button type="submit" class="btn btn-secondary btn-sm">
<i class="fas fa-save"></i>
</button>
</form>
</td>
</tr>
}
As you can see, the last column is a form. What I want done is to be able to submit to my OnPost method, the order id (hidden input element in the form) and the selected state (select in element the form). However, these parameters always show up as null in the method. I'm guessing it has something to do with the fact that, because there are multiple asp-for elements for the same property name (one for each form - each order/row), Razor gets confused and doesn't know which one to send.
Is there a way around this?