Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

Can I use HTML tag helper of ASP NET framework in ASP.NET Core?

TagHelpers NuGet package to enable tag helpers in ASP.NET Core application. This package is not compatiable ASP.NET Web Application (. Net Framework).

How pass multiple parameters in URL in ASP NET MVC?

you could add a route like: routes. MapRoute( "ArtistImages", // Route name "{controller}/{action}/{artistName}/{apikey}", // URL with parameters new { controller = "Home", action = "Index", artistName = "", apikey = "" } // Parameter defaults ); and a method like the first example above.

How would you use the input tag helper to bind an input element to an expression in a razor view file?

The Input Tag Helper binds an HTML <input> element to a model expression in your razor view. The Input Tag Helper: Generates the id and name HTML attributes for the expression name specified in the asp-for attribute. asp-for="Property1.


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

Example:

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

You might want to apply the following syntax.

<a asp-controller="Member"
   asp-action="Edit"
   asp-route-level="3"
   asp-route-type="full"
   asp-route-id="12">Click me</a>

That will produce the call route like this.

/Member/Edit/3/full/12

Then you can receive it in the method as shown below.

[Route({level}/{type}/{id})]
public IActionResult Edit(int level, string type, int id) { ... }

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.


if you want to put variable id into link in grid or table something below code can be used

[HttpGet]
[Route("/Product/GetProduct/{id}")]
 public ActionResult GetProduct(string id)
 {
      ViewBag.CaseId = id;
      return View();
 }


 <a  asp-controller="Product" asp-action="GetProduct" asp-route-id="@item.id" >ProductName</a>