How to specify link parameters in Anchor Tags

Anchor tag helper in Asp.Net core allows you to specify parameter values in the tag that builds complete URL for the action. For most of the cases, specifying asp-controller and asp-action attributes are the ones you will need to construct URL that will be used to populate href attribute of anchor tag. The example could look like below.

<a asp-controller="Organization" asp-action="DeleteBranch">Delete</a>

Above tag will build URL as "/organization/deletebranch. Sometime you have to pass additional parameters in URL for actions. E.g. if I want to edit some model, then I may have to pass identifier value in URL or route. To facilitate that will use asp-route-{parametername} attribute and set the value in that attribute.

<a asp-controller="Organization" asp-action="EditBranch" asp-route-id="@branch.Id">Edit</a>

In my case above tag will generate URL as "/organization/editbranch/1". Then controller can extract value of "id" and do the job.

comments powered by Disqus

Search

Social

Weather

15.7 °C / 60.3 °F

weather conditions Clear

Monthly Posts

Blog Tags