按下拉列表值调用视图

时间:2014-09-11 06:53:42

标签: javascript asp.net-mvc-5

我有一个html.dropdownlist,其中包含ochange事件。我需要使用ajax或javascript函数调用控制器操作方法,并根据过滤器值返回视图

我尝试像下面哪些不起作用,为什么?

<script type="text/javascript">
$(function() { 
        $('#Projcbo1').change(function () {
            // fetch the newly selected value
            var selectedValue = $(Projcbo1).val();
            // send it as an AJAX request to some controller action
            $.post('@Url.Action("ProjCBOItemSelected")', { value: selectedValue }, function (result) { $("#resultContainer").html(result); });
        });
});
</script>

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法来实现这一目标。

 <script>
     $(function() { 
            $('#ddl').change(function () {

                $.ajax({
                    url: '@Url.Action("actionname", "controllername")',
                    type: 'GET',
                    dataType: 'html',
                    data: {Id: $(this).val() },
                    success: function (result) {

                        $('#div_to_load_the_content').html(result);

                    },
                    error: function (error) {

                    },
                });
            });
        });
    </script>

如果有帮助,请告诉我。

相关问题