简体   繁体   中英

How to pass multiple actions in asp.net core 2.0 razor page using Url.Action

I want to use @Url.Action to pass multiple parameters through the URL in an ASP.NET Core 2.0 Razor Page. I don't know which tag helper I should use.

@model Memberships.Models.SmallButton

<a asp-page="@Url.Action(Model.Action)@Model.ActionParameters" 
   class="btn @Model.ButtonType btn-sm">
     <span class="glyphicon glyphicon-@Model.Glyph"></span>
     <span class="sr-only">@Model.Text</span>
</a>

As far as I know you cannot do that with AnchorTagHelper . If you want to add parameters to it then you have to do this one by one:

<a asp-action="Edit" asp-route-id="@Model.Id" asp-route-something="Something">Link</a>

If you want to use Url.Action then you have to pass it via href parameter:

<a href="@Url.Action(Model.Action)">Link</a>

You can use UrlHelper.Action(string action, object values) to pass additional route values:

<a href="@Url.Action(Model.Action, Model.ActionParameters)">Link</a>

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