我有以下方法:
[Route("GetEditorialRequestsByCoordinates/{lat:min(-90):max(90)}/{lng:min(-180):max(180)}")]
[AutomapperExceptionApiFilterAttribute]
public HttpResponseMessage GetEditorialRequestsByCoordinates(double lat, double lng)
{
}
我打电话时工作正常......
GET /v1/api/request/GetEditorialRequestsByCoordinates/48/2
但我希望像这样传递双重值:
GET /v1/api/request/GetEditorialRequestsByCoordinates/48.999/2.777
我收到了错误(找不到404)。好像,它找不到合适的路线方法。 我试图通过以下方式设置路线:
[Route("GetEditorialRequestsByCoordinates/{lat:double:min(-90):max(90)}/{lng:double:min(-180):max(180)}")]
......但它也不起作用。
我该如何解决?
答案 0 :(得分:7)
只需在URL的末尾添加一个/就更正了。看起来路由引擎将其视为2.777文件扩展名,而不是输入参数。
此外,看起来您可以注册一个自定义路由,当使用内置帮助程序生成链接时,该路由会自动在URL末尾添加一个尾部斜杠。
他最简单的解决方案是将以下行添加到RouteCollection中。不确定如何使用该属性,但在RouteConfig中,您只需添加:
routes.AppendTrailingSlash = true;
有关详细信息,请查看here。
最后一个max和min函数适用于整数
max:匹配具有最大值的整数。 {X:最大(10)} 强>
我认为它不适用于双倍。