This table correctly populates with @device.DeviceId but does not pass @device.DeviceId to the controller action.
<table border="1" cellpadding="10">
@foreach (var device in @Model.Devices)
{
<tr>
<td>@device.DeviceId</td>
<td>@device.DeviceName</td>
<td>
<a asp-action="DeleteDevice"
asp-controller="Device"
asp-route-id="@device.DeviceId" asp->
Delete
</a>
</td>
</tr>
}
</table>
The controller action signature is
public async Task<IActionResult> DeleteDevice(int deviceId)
The action is called but deviceId = 0.
How do I ensure @device.DeviceId is correctly passed to the action?
Either change the controller action to:
public async Task<IActionResult> DeleteDevice(int id)
or, change the a tag so that the asp-route-* attribute matches the name of the parameter, like so:
<a asp-action="DeleteDevice"
asp-controller="Device"
asp-route-deviceId="@device.DeviceId">
Delete
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With