How to use / pass hidden field value in ActionLink

I have a problem passing a hidden field value in the actionlink parameter:

ProductView:

@Html.ActionLink("ProductCompare", 
                 "ProductCompare", 
                 new { ProductIds= **hdnSelectedProductId**)
@Html.Hidden("hdnSelectedProductId")

Controller action:

public ActionResult ProductCompare(string ProductIds)
{
    return View();
}

When a user selects a product, I continue to enter product identifiers in hdnSelectedProductId using javascript. Now, when the user clicks on the ProductCompare link, I want to pass this hidden field value to the controller. Please guide me.

+2
source share
1 answer

One solution is to use jQuery to attach a click event that will read the hidden field and attach it to the link href attribute.

, , , ViewData .

0

All Articles