ASP.Net MVC Ajax call in View to Controller not Working

54 viewsajaxasp.net mvc
0

I have a view, that when loaded, it should send a request back to the controller to change do an async task.

The AJAX call in the view:

@section Scripts
{
    <script>
        $(document).ready(function () {
            $.ajax({
                 url: '@Url.Action("GetWifis", "RobotSsh")',
                 type: 'POST',
                 success: function () {
                     console.clear();
                     console.log("success");
                 },
            });
        });
    </script>   
}

The method in the controller:

    [HttpPost]
    public async Task<IActionResult> GetWifis(RobotSshModel model)
    {
        await model.GetAllWifiSsids();
        model.RobotPassword = "test";
        
        // Render the page again, keeping the data user has entered by supplying the model.
        return View("~/Views/Home/RobotSsh.cshtml", model);
    }

The "success" string is actually logged to the console, even if the GetWifis function is not called.

I have tried to change to GET request, partial views, other stuff, nothing works.