Daniel Orlan Daniel Orlan - 3 months ago 23
Ajax Question

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

Answer

Try lowercase "url":

$.ajax({...

    url : '...'

    });