I'm trying to handle these requests with the same controller action:
localhost:52000/api/messages
localhost:52000/api/messages?page=1
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 thegetMessage()
action?
Thanks!
try this
[Route("api/messages")]
[HttpGet]
public HttpResponseMessage getMessage(DateTime? date = null, int? page = null)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.