I have previously implemented a onclick event inside a <label> tag as shown below
<label onclick="window.location='/edit/@(editId)'">edit<lable>
but now, I want to use only tag helpers to generate links using tag helpers like asp-page, asp-route-editId etc.
how can I build above onclick url with asp-tag helpers
In this scenario, you have to create the url directly, you can't use Anchor Tag Helper attributes because they create attributes like
hreffor you. But here you have to create the link directly and use it in theonclickevent:if using MVC:
if using Razor Page:
Finally, your code should be as follows(for razor page link)
One important note:
If your input parameter name is
editid, you can omit the parameter name in route values, but if it has a different name, for example,itemId, you must explicitly specify the parameter name. As follows