NULL
NULL

Reputation: 1589

add parameters to html.actionlink

I have a controller "myController" that has a function called "printDetails(string id)" I have a view that calls the

@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>

thanks for all your responses.

Upvotes: 0

Views: 863

Answers (1)

Charaf JRA
Charaf JRA

Reputation: 8334

You can add an id to your ActionLink and then select it using jQuery :

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

this will generate an html link :

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

And then select your link using jquery and change href attribute :

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

Using pure Javascript :

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

Upvotes: 1

Related Questions