How to use/pass hidden field value in ActionLink

血红的双手。 提交于 2019-12-11 00:52:05

问题


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:


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.



来源:https://stackoverflow.com/questions/10464003/how-to-use-pass-hidden-field-value-in-actionlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!