将参数添加到html.actionlink

本文关键字:html actionlink 添加 参数 | 更新日期: 2023-09-27 18:28:59

我有一个控制器"myController",它有一个名为"printDetails(string id)"的函数我有一个称为的视图

@Model.myControllers
//I output files here and user can download to a file, or by selecting an item from the drop down menu and pass it to the function "printDetails"
html.actionlink("download","printDetails")
html.dropdownlist("fromdb",null,"--select--", new{onchange="myJSFunction(fromdb)"})
<script>
myJSFunction(fromdb)
{
//how do i pass "fromdb" as a paramenter to "printDetails?id=fromdb" //myController/printDetails
}
</script>

感谢您的回复。

将参数添加到html.actionlink

您可以向ActionLink添加一个id,然后使用jQuery:选择它

  <%= Html.ActionLink("download", "printDetails", "MyController", null, new {id = "someID" }) %> 

这将生成一个html链接:

 <a href="/MyController/printDetails" id="someID">download</a>

然后使用jquery选择您的链接并更改href属性:

$('#someID').attr('href','/MyController/printDetails?id='+fromdb);

使用纯Javascript:

document.getElementById('someID').href='/MyController/printDetails?id='+fromdb;