0

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

感谢您的所有回复。

4

1 回答 1

1

您可以向 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;
于 2013-08-25T01:05:33.903 回答