【发布时间】:2013-07-02 12:58:52
【问题描述】:
我是使用 aspnet web api 进行属性路由的新手。
public class UsersController : ApiController
{
[GET("users/me/brands/{id}")]
public IEnumerable<Brand> GetBrands(long id)
{
return _repository.FindByUser(id);
}
}
但我无法执行此操作。我尝试了很多方法:
http://example.com/api/users/brands/4http://example.com/api/users/brands?id=4http://example.com/users/brands?id=4http://example.com/users/brands/4
PS:我也映射为[GET("api/users/me/brands/{id}")]
我错过了什么?
【问题讨论】:
-
您的属性路由显示
users/me/brands/{id},而您使用的是api/users/brands/4等。为什么?如果您希望执行此操作,则应该遵循模板的建议...即users/me/brands/4... -
@KiranChalla api 是默认前缀。没有它,mvc 不会路由到我的控制器
标签: c# asp.net-web-api wcf-web-api