Elvin Mammadov Elvin Mammadov - 1 year ago 69
C# Question

How to add link parameter to asp tag helpers in ASP.NET Core MVC

I have a lot of experience with ASP.NET MVC 1-5. Now I learn ASP.NET Core MVC and have to pass a parameter to link in page. For example I have the following Action

public ActionResult GetProduct(string id)
ViewBag.CaseId = id;
return View();

How can I implement the link for this action using tag helpers?

<a asp-controller="Product" asp-action="GetProduct">ProductName</a>

Answer Source

You can use the attribute prefix asp-route- to prefix your route variable names.


<a asp-controller="Product" asp-action="GetProduct" asp-route-id="10"> ProductName</a>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download