【发布时间】:2013-07-03 15:22:23
【问题描述】:
假设我有以下动作;
// api/products
public IEnumerable<ProductDto> GetProducts()
public ProductDto GetProduct(int id)
// api/products/{productId}/covers
public IEnumerable<CoverDto> GetCovers(int productId)
创建路径以用作“主”产品的快捷方式的最佳方法是什么?即api/products/master
我尝试添加一个主控制器,并将上面的内容路由到它,但我收到以下错误:
The parameters dictionary contains a null entry for parameter 'id'
of non-nullable type 'System.Int32' for method 'ProductDto GetProduct(Int32)'
in 'ProductsController'. An optional parameter must be a reference type,
a nullable type, or be declared as an optional parameter.
为了解决这个问题,我尝试将正常的产品路线更新为api/products/{id:int},但无济于事。
我想得到以下结果;唯一的区别是“主”产品将通过 code 而不是 id
获得api/products
api/products/1
api/products/1/covers
api/products/master
api/products/master/covers
【问题讨论】:
标签: c# rest asp.net-web-api asp.net-web-api-routing