I am trying to call a C# code from JavaScript in an MVC .NET application, excluding Blazor. The following code snippet is specific to the .NET and MVC stack, not a generic AJAX query like another one on Stack Overflow. After making the Ajax call, there are no error messages, and it simply proceeds to the next statement. There might be two possible issues that I can identify. Firstly, my URL: '/Home/CreatePostcodeFromCoordinates' could be incorrect. Secondly, maybe my C# assembly is not part of the assembly or something similar. Coming from a database background, I admit I am not very experienced with web technologies, but fixing this shouldn't be too hard, right? I can't seem to find anything else that is wrong. Also, does the return value from the C# code need to be in a special format, or is returning a string (as currently implemented) sufficient?
console.log("just before /Home/CreatePostcodeFromCoordinates");
$.ajax({
type: "POST",
url: '/Home/CreatePostcodeFromCoordinates',
data: { param1: longitude, param2: latitude },
success: function (response) {
console.log('success');
console.log(response);
},
error: function (error) {
console.error(error);
}
});