简体   繁体   中英

.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>

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?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 ?

I found a workarout for anchor using Html.ActionLink , but not for 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:

https://localhost:5001/Home/Index/1?id2=2

The request payload:

在此处输入图像描述

Controller action:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM