'.NET Core 6 - How to pass data on click
I have a foreach loop that iterates through a Model and displays the data in a table. I want to pass the id (or any data from the model) to an element outside the foreach loop whenever I click on a button that corresponds to an entry in the loop, how can I do so?
Example:
<tbody>
@foreach (var incident in Model)
{
<tr>
<th>@incident.Title</th>
<td>@incident.CustomerId</td>
<td>@incident.ProductId</td>
<td>@incident.DateOpened</td>
@{
var id = @incident.IncidentId;
}
<td><a asp-controller="Incident" asp-action="Edit" asp-route-id="@incident.IncidentId" ><i class="fa-solid fa-pen-to-square"></i></a></td>
<td >
<i class="fa-solid fa-trash-can hover:cursor-pointer" > <<-- When clicked, store the model id, modelId = @incident.IncidentId
</i>
</td>
</tr>
}
</tbody>
//Now I should have access to the exact variable (id) and pass it to other elements
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
