Reputation: 105
I am using the tag helper normaly like this:
<a asp-action="ActionName" asp-route-id="@item.id" class="btn btn-sm btn-info mt-2">Edit</a>
or <button asp-action="ActionName" asp-route-id="@item.id class="btn btn-sm btn-info mt-2""></button>
However, when I try to use the tag helper with a composite primary key I am unable to get the link right.
asp-route-id="@item.ID1, @item.ID2"
= ActionName/Id1,Id2
asp-route-id="@[email protected]"
= ActionName/Id1%3FID2%3DId2?
How can I use the asp-route-id
and have it putput /Id1?ID2=Id2
or /Id1?{SpecifiedName}=Id2
?
I found a workarout for anchor
using Html.ActionLink
, but not for button
Upvotes: 1
Views: 4658
Reputation: 8459
This is a working demo.
<form method="post">
<label>Username:</label>
<input type="text" name="username" class="form-control" />
<label>Password:</label>
<input type="password" name="password" class="form-control" />
<button asp-action="Index" asp-route-id="1" asp-route-id2="2" class=" btn btn-info ">Edit</button>
</form>
View:
After submit the button, the generate url:
https://localhost:5001/Home/Index/1?id2=2
The request payload:
Controller action:
Upvotes: 3