我需要实现以下 WebAPI 方法:
/api/books?author=XXX&title=XXX&isbn=XXX&somethingelse=XXX&date=XXX
所有查询字符串参数都可以为空。也就是说,调用者可以指定从 0 到所有 5 个参数。
在MVC4 beta中,我曾经做过以下事情:
public class BooksController : ApiController
{
// GET /api/books?author=tolk&title=lord&isbn=91&somethingelse=ABC&date=1970-01-01
public string GetFindBooks(string author, string title, string isbn, string somethingelse, DateTime? date)
{
// ...
}
}
MVC4 RC 不再像这样了。如果我指定的参数少于 5 个,它会回复404
说:
在与请求匹配的控制器“Books”上未找到任何操作。
什么是正确的方法签名,使其表现得像以前一样,而不必在 URL 路由中指定可选参数?