2013-08-25 38 views
0

我有一個控制器「myController的」,有一個叫「printDetails(字符串ID)」 功能我有一個調用參數添加到html.actionlink

@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

您可以將ID添加到您的ActionLink,然後使用選擇它的jQuery:

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

這將生成一個HTML鏈接:

​​

,然後使用jQuery和變化的href選擇你的鏈接屬性:

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

使用純Javascript:

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

優秀的,我可以做到這一點簡單的JS,不知何故未啓用jQuery的運行對我和我沒有時間去找出原因:( – NULL

+0

好它現在做 –

+0

涼,所以在我的控制器做printDetails(串ID)會知道是ID從DB?涼。謝謝。 – NULL