문제

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