質問

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