Question

I have this in my View:

@Html.DropDownList("dropBox", (List<SelectListItem>)ViewBag.SelectedListItems)

I would like to get the selected value from the dropBox and post it back to the controller using like this:

@Html.ActionLink("Add","AddAction", "AddController", new {@accessID = *here*})

here is where I'd just like to add "dropBox".SelectedValue, but how do I do this?

How else could I post back the SelectedValue of the dropBox?

Was it helpful?

Solution

the actionlink helper is rendered at the server, the value of the dropdown is selected by the user at the client side

so what you can do is something like this:

        <a id='badd'>add</a>
        <script>
         $('#badd').click(function(e){
             e.preventDefault();
             window.location.replace = 
    '<%=Url.Action("Add","AddAction", "AddController")%>' + '?accessID='+ $('#dropBox').val();
             });
        </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top