Forum Discussion

panos2024b's avatar
panos2024b
Copper Contributor
Oct 28, 2024
Solved

ajax and connection to mvc .net

I need to access some c# code from javascript in MVC ,NET (not blazor). I have the below. This is very specific to .NET and MVC stack and not a generic ajax question like another one in stack overfow...
  • panos2024b's avatar
    Oct 31, 2024
    It worked by this async: false,. However async: = false, is deprecated apparently soon and needs the new way which i will investigate and change in my code
    C#

    public string CreateCoordinatesFromPostcode(string postcode)
    {
    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;

Resources