user979331 user979331 - 3 months ago 9
Ajax Question

jQuery ajax call to ASP.NET calling wrong method

I have this ajax call here:

$.ajax({
type: "GET",
url: "/api/action/deleteData?issueID=16",
success: function (data) {
console.log(data)
},
failure: function (errMsg) {
alert('Failed, somthing went wrong, please try again!');
}
});


which is trying to call this method

public string deleteData(string issueID)
{
return "aaa";
}


however, this is calling the wrong method, its calling a method with no parameters. Why is it doing this and how can I fix this?

The action is correct or otherwise it wouldn't be going into the other method.

When I manually try to call this method with the URL, its returns the data from the wrong method. I dont get it.

Answer

Apply [ActionName("deleteData")] to your WEB API action and it will work.I justed tested on my side and it's working perfectly.Below is my ApiController:

public class actionController : ApiController
{
    public string deleteData()
    {
        return "deleteData";
    }

    public string doSomething()
    {
        return "doSomething";
    }

    [ActionName("deleteData")]
    [HttpGet]
    public string deleteData(string issueID)
    {
        return "aaa";
    }
}
Comments