How To Send ActionLink Parameters With routevalue in asp.net mvc 5 to controller with jquery

有些话、适合烂在心里 提交于 2019-12-08 07:32:29

For example You can achieve this with jQuery function on dropdown value change event and setting element href attribute.

If You want, change <select /> to @Html.DropDownListFor() or @Html.DropDownList()

<script type="text/javascript">
    $(document).ready(function () {
        $('.myClass').change(function () {
            $('.mbtn').attr('href', '/MyController/CityInfo?cityid=' + $(this).val());
        });
    })
</script>

<select class="myClass">
    <option value="1">Texas</option>
    <option value="2">Sao Paulo</option>
    <option value="3">Mexico</option>
</select>

@Html.ActionLink("More Info", "CityInfo", null, new { @class = "mbtn" })

For more parameters You can for every dropdown set class='myClass' and different id. With it You should be able to use it as:

<script type="text/javascript">
    $(document).ready(function () {
        $('.myClass').change(function() {
            $('.mbtn').attr('href', '/MyController/CityInfo?cityid=' + $('#cityId').val() + '&userId=' + $('#userId').val());
        });
    })
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!