This seems easy but is not just working for me. I have the following code to run a method in my HomeController from my JavaScript file:
function(id) {
alert("here");
$.ajax({
url: '/HomeController/MethodName',
data: { id: id },
success: function(data){
alert('Sucess ' + data);
}
});
}
My method is
public string MethodName(int id)
{
return id.ToString() + "test ";
}
The view calling the javascript has the following scripts defined: jquery.unobtrusive-ajax.min.js, MicrosoftMvcAjax.js, MicrosoftAjax.js, validate.unobtrusive.min.js, jquery.validate.min.js
But is is not just working. Nothing happens. The first alert of the function do show up. But nothing else after that.
{on the first line, afterfunction(id)- dunno if that's a typo, or if it will have any effect though. If it is in your code, it could be causing your function to just bealert("here"), which would explain your behaviour - I'm not sure what the browser might do to try to cope.