user576510
user576510

Reputation: 5905

Multiple actions were found that match the request?

I m new to WebAPI and just exploring its default sample "value" controller which is there out of box with project.

I see it was already having two Get methods:

      // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

I tried and changed int id with a complex type and received "Multiple actions were found that match the request"

Why is that it was working fine beofre ?

My route is defuatl:

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

I m passing a complex object in body using Get methoed, I know it is not Restful way but please help me understand it.

Much appreciated.

Upvotes: 0

Views: 418

Answers (1)

Hadee
Hadee

Reputation: 1402

You can use ActionName annotation for this issue. For example use:

 [ActionName("IEnumerableGet")]
 public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

So you can call IEnumerableGet to have this method get called.

Upvotes: 1

Related Questions