将参数添加到html.actionlink

时间:2013-08-25 00:58:45

标签: c# jquery asp.net-mvc

我有一个控制器“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>

感谢您的所有回复。

1 个答案:

答案 0 :(得分:0)

您可以向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;