我有一个控制器“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>
感谢您的所有回复。
答案 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;