从DropDownList获取值,在ActionLink中使用它(ASP.NET MVC4)

时间:2021-12-13 06:40:34

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:

我想从dropBox中获取所选值并使用以下方法将其发回控制器:

@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?

这里是我想添加“dropBox”.SelectedValue的地方,但我该怎么做呢?

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

我怎样才能回发dropBox的SelectedValue?

1 个解决方案

#1


1  

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

actionlink帮助程序在服务器上呈现,下拉列表的值由用户在客户端选择

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>

#1


1  

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

actionlink帮助程序在服务器上呈现,下拉列表的值由用户在客户端选择

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>