ASP.NET Ajax doesnt call Url

ASP.NET Ajax doesnt call Url

本文关键字:call Url doesnt Ajax NET ASP      更新时间:2023-09-26

Ajax似乎不工作在我的视图。我将问题简化为让一个按钮通过ajax调用控制器方法。结果是视图的相同html被附加到div中。通过调试器查看,调用的是相同的GetEventForm url,而不是TestAjax

GetEventForm.cshtml中的按钮

<input type="button" id="btn" value="Test Ajax" class="btn-sm"/>

<div id="rule"> </div>

Ajax

<script type="text/javascript">
    $(document).ready(function () {
        $('#btn').on('click', function() {
            $.ajax({
                type: 'GET',
                cache: false,
                Url: '@Url.Action("TestAjax","Events")',
                success: function(result) { $("#rule").html(result); }
            });
        });
     });
 </script>

    public string TestAjax()
    {
        return "Response string from Controller!";
    }
点击前

点击后

试试小写的"url":

$ . ajax({…

    url : '...'
    });