I want to trigger the Controller Action when I click on a button, and I tried to implement some JQuery code to do that, however the click is not triggering properly.
I have the following code :-
<script type="text/javascript">
$(document).ready(function () {
$("#btnLoadData").click(function() {
var ResXName = $('#ResXName').val();
var LangID = $('#LangID').val();
var url = "../Home/LoadResXFile";
e.preventDefault();
$.getJSON(url, { value: ResXName, langID: LangID }, function (data) {
alert('clicked!');
});
});
});
</script>
<div class="main-content">
<input type="button" id="btnLoadData" value="Load Data" />
</div>
When I move the alert above the $getJSON, it works, so the button is being clicked correctly, however when I move the alert inside the $getJSON, I am not getting any alerts, and also the controller action is not being triggered.
Am I missing something?
Thanks for your help and time
My problem was not actually in the aspx, but inside the controller. I was returning :-
which apparently is wrong since there is nothing to return. I changed it to :-
and now its working!
Thanks for all your help and time!