Finally this is how i managed to fix it: I am a calling a C# method here in MVC. Make sure your C# method is not declared as static. Just like this. Also i spend probably 8 hours day trying to understand why i could not get any results back. You need the async = false option. Otherwise you will spend similar amount of time if not more!
C# public string CreateCoordinatesFromPostcode(string postcode) { // logic string result = "XXXXXX" // your logic return result; }
JavaScript
let result = '';
$.ajax({
type: "POST",
url: '/clib/CreateCoordinatesFromPostcode',
async: false,
data: { postcode: postcode },
success: function (response) {
result = response;
},
error: function (error) {
console.error(error);
}
});
console.log("just after /clib/createCoordinatesFromPostcode");
return result;