Search code examples
c#asp.net-coreasp.net-core-mvcasp.net-core-tag-helpers

What is the Asp.Net Core TagHelper equivalent of Html.ActionLink with script


I want to prompt a confirmation dialog before deleting. I found this answer here that works great

@Html.ActionLink(
          "Delete",
          "Delete",
          new { id = post.OriginalPost.ID },
          new { onclick = "return confirm('Are you sure you wish to delete this post?');" });

but as I understand in Core one should avoid the use of ActionLinks. So are there any tag-helpers or different ways to do this?


Solution

  • You would normally use the AnchorTagHelper:

    <a asp-action="Delete" asp-route-id="@post.OriginalPost.ID" 
        onclick="return confirm('Are you sure you wish to delete this post?');">Delete</a>