2

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.

4
  • is the asp.net web forms? or MVC? Commented Aug 5, 2016 at 19:33
  • This is asp.net MVC Commented Aug 5, 2016 at 19:41
  • "its returns the data from the wrong method" what method is being called/returning data? there may be an issue with MVC not reading the route correctly Commented Aug 5, 2016 at 20:01
  • What happens if you change your action signature to accept an int parameter instead of string? Otherwise, I think we may need to see your route definitions/setup. Commented Aug 5, 2016 at 21:40

2 Answers 2

4

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";
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure if the way you pass your parameter is correct. I tend to always use the data property of the ajax call to pass in my parameter.

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

Hope it helps

3 Comments

Nope that did nothing
Hum I wonder i wonder if it's because you are using an api. Have you tried the following: url: "/api/action/deleteData/16"
apis, webservices and regular mvc methods take parameters differently

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.