Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request matched multiple actions resulting in ambiguity for actions with different parameters in ASP.NET 5 / MVC 6

I have a simple route in my project:

routes.MapRoute(
      name: "api",
      template: "api/{controller}/{action}");

In my controller I have two actions:

    [HttpGet]
    public string Get(string value)
    {
        return value;
    }

    [HttpGet]
    public string Get(int id)
    {
        return id.ToString();
    }

Now when I try to do a url like api/controller/get?id=1 it does not work because the framework cannot distinguish between two actions. As far as I remember it did work pretty well in ordinary web api because it's obvious that this url matches only one of the actions based on it's parameter. Did I do something wrong or it's not supported in the new MVC6?

like image 542
Ilya Chernomordik Avatar asked Oct 19 '22 20:10

Ilya Chernomordik


1 Answers

Did I do something wrong or it's not supported in the new MVC6?

MVC Action Selector dosen't regard Action's parameters during select action. Therefore you can't have two actions correspond one route template. Except e.g actions have different Action Constraints (HttpPost, HttpGet).

Choose action logic in code.

In theory choosen logic between some actions based on parameters have to be into SelectBestActions method, but it do nothing

like image 143
Stas Boyarincev Avatar answered Oct 21 '22 14:10

Stas Boyarincev