In my blazor app I have a component that has a button and a bootstrap collapse controlled by the button. Everything works fine when I only use that component once on a page but if I use it multiple times on a page then the button for one will also trigger the collapse element in the other since their IDs seem to be static. Is there a way around this?
Here is the code for the component
<button class="btn btn-primary form-control" type="button" data-toggle="collapse" data-target="#divCollapse" aria-expanded="false" aria-controls="divCollapse">
@Technician.Name
</button>
<div class="collapse" id="divCollapse">
<div class="card card-body">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Assigned To</th>
</tr>
</thead>
<tbody>
@foreach (var task in _repo.GetTasksByTechnician(Technician).ToList())
{
<tr>
<td>@task.Id</td>
<td>@task.AssignedTo</td>
</tr>
}
</tbody>
</table>
</div>
</div>
@code {
[Parameter]
public Technician Technician { get; set; }
}
Here is the code in the page that I use to create the component:
@foreach (var tech in _technicians)
{
<PersonComponent Technician="@tech"></PersonComponent>
}