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?

有帮助吗?

解决方案

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top