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?

Était-ce utile?

La 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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top