I have sample code like this:
If you want to call an action from your JavaScript, one way is to embed your JavaScript code, inside your view (.cshtml
file for example), and then, use Razor, to create a URL of that action:
$(function(){
$('#sampleDiv').click(function(){
/*
While this code is JavaScript, but because it's embedded inside
a cshtml file, we can use Razor, and create the URL of the action
Don't forget to add '' around the url because it has to become a
valid string in the final webpage
*/
var url = '@Url.Action("ActionName", "Controller")';
});
});