ASP.NET Web API中的可选查询字符串?

我正在尝试使用相同的控制器操作来处理这些请求:

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

我做了如下的控制器动作:

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

但这仅在查询字符串值为null时有效,而在实际查询为null时无效。

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

  • 不起作用(找不到操作):localhost:52000/api/messages

  

我如何使每个api/messages请求都由   getMessage()动作?

谢谢!

yanchenghua2009 回答:ASP.NET Web API中的可选查询字符串?

尝试

[Route("api/messages")]
[HttpGet]
public HttpResponseMessage getMessage(DateTime? date = null,int? page = null)
本文链接:https://www.f2er.com/3059663.html

大家都在问