我正在为WebApi使用http://attributerouting.net/ nuget包。下面是我的两个GET方法和route属性,分别用于list和一个特定的项目:
[GET("api/products/{tenantid}/{channelid}?{skip=0}&{take=20}&{status=1}")]
public IEnumerable<Product> Get(short tenantId, byte channelId, int status, int skip, int take)
[GET("api/products/{tenantid}/{channelid}/{id}")]
public Story Get(short tenantId, byte channelId, long id)但在生成的帮助URI中,显示了三个GET选项。
GET api/products/{tenantid}/{channelid}?status={status}&skip={skip}&take={take}
GET api/products/{tenantid}/{channelid}?id={id}
GET api/products/{tenantid}/{channelid}/{id}即使"id“不是第一个GET方法的参数。如何消除结尾带有"?id={id}“的中间URI?我想我需要一些约束,但是我不能从文档站点中找到它。
发布于 2013-05-17 04:23:14
a. "api/products/{tenantid}/{channelid}",controller="Products",action = "Get“等...
b. "api/products/{tenantid}/{channelid}/{id}",controller="Products",action = "Get"...
现在对于路由'a.',ApiExplorer检查哪些动作可以到达,并且它注意到对于控制器'Products‘和动作'Get',有两个动作可以到达,并且它还尝试查看有多少参数来自路由路径本身,如果动作上有任何参数不是来自路由路径,它会假设它来自您看到的查询string...hence "?id={id}“。希望这能有所帮助。
https://stackoverflow.com/questions/16588261
复制相似问题