0

Is it possible to have multiple Get methods with the same number of parameters? For example, I would like to have a Get(int) and a Get(string). I've tried experimenting with this, but it always seems to hit the Get(string) method and never the one with the int. So is it possible to make these two distinguishable?

SalysBruoga
  • 875
  • 1
  • 9
  • 21
  • 1
    Internally in the code base you can, but I've found it best to apply the `Route` attribute to the overloaded methods to define a different URL signature. – ColinM Dec 05 '16 at 10:57
  • Not sure if it's doable but try casting the input to int? – Alfie Goodacre Dec 05 '16 at 10:59
  • Looks like a duplicate- http://stackoverflow.com/questions/9499794/single-controller-with-multiple-get-methods-in-asp-net-web-api – Souvik Ghosh Dec 05 '16 at 11:07
  • `Get` method itself will not be used by developers(only in tests maybe). So I think more descriptive name will be more readable approach in case of API controller's method – Fabio Dec 05 '16 at 11:11

1 Answers1

1

Yes you can do it but you have to specify different routes for each Get method.

PMerlet
  • 2,568
  • 4
  • 23
  • 39