user2817774
user2817774

Reputation: 25

Web api error Multiple actions were found

I have two methods like below on GridController.

[System.Web.Http.AcceptVerbs("POST")]
[System.Web.Http.ActionName("PostData")]
public List<GridDataRow> PostData(GridDataParam data)

[System.Web.Http.AcceptVerbs("POST")]
[System.Web.Http.ActionName("PostGridDataRow")]
public GridDataRow PostGridDataRow(RowDataParam data)   

I am calling these web api from ajax calls. When I have only one method PostGridDataRow(), it works fine.

The moment I add the second post function PostData() I keep getting error:

Multiple actions were found.

Shouldn't it work fine as I have different action names? I have not defined any routes in route mapping.

Upvotes: 0

Views: 109

Answers (1)

Marius Schulz
Marius Schulz

Reputation: 16440

The issue at hand is that Web API can't pick the one right action method to map your POST request to. You're providing two actions that are equally good matches for a POST request since they're both accepting one complex parameter.

To solve your problem, consider creating two separate controllers with one POST method each.


Try to walk in Web API's shoes: If you were to make the decision which action method to call solely based on incoming data like the following, which one would you pick?

{ foo: "bar" }

Upvotes: 2

Related Questions