0

I'm trying to handle these requests with the same controller action:

  1. localhost:52000/api/messages
  2. localhost:52000/api/messages?page=1
  3. localhost:52000/api/messages?date=2019/29/11&page=1

I made a controller action as following:

[Route("api/messages")]
[HttpGet]
public HttpResponseMessage getMessage(DateTime? date, int? page)

But this only works if the query string value is null, not if the actual query is null.

  • Working: localhost:52000/api/messages?date=&page=

  • Not working (It doesn't find the action): localhost:52000/api/messages

How can I make every api/messages request be handled by the getMessage() action?

Thanks!

1
  • set default value for both the parameters Commented Nov 21, 2019 at 8:56

1 Answer 1

1

try this

[Route("api/messages")]
[HttpGet]
public HttpResponseMessage getMessage(DateTime? date = null, int? page = null)
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.