I'm populating an HTML table with a collection of data items.
But I want each cell to be editable. And so I'm displaying the item fields in controls. For example:
@foreach (FleetRailcarDto railcar in editSection.Railcars)
{
<tr>
<td></td>
<td>
<select asp-for="@railcar.FleetId" asp-items="@Model.FleetOptions" class="form-control-sm edit-fleet-id">
</select>
</td>
<td>
<select asp-for="@railcar.Ownership" asp-items="@Model.OwnershipOptions" class="form-control-sm edit-ownership">
</select>
</td>
<td>
<input asp-for="@railcar.CarType" class="form-control-sm edit-cartype" />
</td>
</tr>
}
This displays fine but it generates the same ID attributes for every table row.
I know I can build the HTML manually, but there are a few things going on here. Has anyone found a way to use asp-for
for variations of the same property without causing duplicate ID attributes?