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
[HttpGet]
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>
asp-route-yourParamName
, for example:asp-route-foo="bar"
You might want to apply the following syntax.
That will produce the call route like this.
Then you can receive it in the method as shown below.
Although, the attribute decorating the method isn't required in MVC, it shows more clearly how to bind the attributes from the link to the passed in parameters in the method.