I have a table displaying object elements from a dynamic list, hence the table should be able to grow and shrink in size, as the user sees fit. How would i be able to get the specific row index?
I basically have a shopping cart, with price, quantity, name and so forth. And lastly, a delete button, that when clicked should delete the current row. So i need to be able to associate the current list element with its respective delete button.
Below is my table:
<div class="customContainer">
<table class="customTable">
<thead class="customHead">
<tr class="customRow">
<th class="customHead2">Product</th>
<th class="customHead2">Quantity</th>
<th class="customHead2">Price</th>
<th class="customHead2">Total</th>
<th class="customHead2">Remove</th>
</tr>
</thead>
<tbody class="customBody">
@foreach (var itemList in Model)
{
<tr class="customRow">
<td class="customData">@itemList.Name</td>
<td class="customData">@itemList.Quantity</td>
<td class="customData">@itemList.Price</td>
<td class="customData">@itemList.Total</td>
<td class="customData"><button class="btn-dark">Delete</button></td>
</tr>
}
</tbody>
</table>
</div>
Would there be a way to give the delete button, 'btn-dark' , a dynamic id that increments/decrements as the table grows/shrinks?