ASP.NET Web API 中的可选查询字符串?
Optional query strings in ASP.NET Web API?
我正在尝试使用相同的控制器操作来处理这些请求:
localhost:52000/api/messages
localhost:52000/api/messages?page=1
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
How can I make every api/messages
request be handled by the
getMessage()
action?
谢谢!
试试这个
[Route("api/messages")]
[HttpGet]
public HttpResponseMessage getMessage(DateTime? date = null, int? page = null)
我正在尝试使用相同的控制器操作来处理这些请求:
localhost:52000/api/messages
localhost:52000/api/messages?page=1
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
How can I make every
api/messages
request be handled by thegetMessage()
action?
谢谢!
试试这个
[Route("api/messages")]
[HttpGet]
public HttpResponseMessage getMessage(DateTime? date = null, int? page = null)