Daniel Orlan
Daniel Orlan

Reputation: 83

ASP.NET Ajax doesnt call Url

Ajax doesnt seem to be working on my View. I simplified my problem down to having a button call a controller method via ajax. The result is the same html of the view is being appended to the div. Looking through the debugger, the same GetEventForm url is called and not TestAjax

Button in 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>

Controller

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

Before Click

After Click

Upvotes: 1

Views: 105

Answers (1)

David Broderick
David Broderick

Reputation: 112

Try lowercase "url":

$.ajax({...

    url : '...'

    });

Upvotes: 1

Related Questions