How to use/pass hidden field value in ActionLink

2019-07-16 17:46发布

I have problem passing hidden field value in actionlink parameter:

productView:

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

Controller Action:

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

When user select any product i keep putting product ids in hdnSelectedProductId using javascript. Now when user click on ProductCompare link i want to pass this hidden field value to controller. Please guide me.

1条回答
祖国的老花朵
2楼-- · 2019-07-16 18:32

One solution is to use jQuery to attach a click event which would read the hidden field and append it to the link's href attribute.

The other solution is to store the value, if you know what it would be, in ViewData and use it instead of hidden field value.

查看更多
登录 后发表回答