views:

26

answers:

1

I have a DropDownList:

<%: Html.DropDownListFor(
        c => c.DataTextField, 
        Model, 
        "Please Select Contract", 
        new { id="selected-contract"}) %>

And I want to access the selected item id in a Html.ActionLink:

<%: Html.ActionLink(
        "Add Contract Item", 
         "CreateContractItem", 
         "Contract", 
         [WHAT GOES HERE?], 
         new { @class="button"}) %> 

Does anyone know how I access the selected item ID to pass to the Controller?

A: 

You'd either need to:

  1. Fire a javascript function when the selected-contract value changes to find the action link <a href=....> and modify the url accordingly. Simple to implement but requires javascript.

  2. Implement the view as a form and POST the selected-contract and instead of using an action link, use a submit button. Simple to implement, no javascript involved

  3. Fire a javascript function when the selected-contract value changes and round trip with a HTTP POST to the server to generate the action link on the server side. Not great.

Kev
Thanks Kev. I went with option 2.
abarr