[英].net core asp-route-id tag helper with multivariable id
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>
或
<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="@item.ID1, @item.ID2"
= ActionName /Id1,Id2
asp-route-id="@item.ID1?ID2=@item.ID2"
= ActionName /Id1%3FID2%3DId2?
asp-route-id="@item.ID1?ID2=@item.ID2"
= ActionName /Id1%3FID2%3DId2?
How can I use the asp-route-id
and have it putput /Id1?ID2=Id2
or /Id1?{SpecifiedName}=Id2
?如何使用
asp-route-id
并让它 putput /Id1?ID2=Id2
或/Id1?{SpecifiedName}=Id2
?
I found a workarout for anchor
using Html.ActionLink
, but not for button
我找到了一个使用
Html.ActionLink
anchor
的解决方法,但不是button
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:提交按钮后,生成url:
https://localhost:5001/Home/Index/1?id2=2
The request payload:请求有效载荷:
Controller action: Controller 动作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.