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?

4
  • 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. Commented Dec 5, 2016 at 10:57
  • Not sure if it's doable but try casting the input to int? Commented Dec 5, 2016 at 10:59
  • Looks like a duplicate- stackoverflow.com/questions/9499794/… Commented Dec 5, 2016 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 Commented Dec 5, 2016 at 11:11

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

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.