【发布时间】:2016-02-04 11:01:06
【问题描述】:
正如命名约定所说,WebApi 控制器操作名称应为 Get()、Put()。 Post() 等。但是告诉我,如果我有一个控制器作为 CustomerController,现在我想在其中有两个操作。一个是 GetCustomerById(int id),另一个是 GetCustomerByAge(int age)。这里两个动作都接受一个参数作为 int。
所以,如果我想让 url 像 "api/customer/" 一样对用户友好,我也想遵循操作命名约定,例如 Get(int id)/Get( int age),我该怎么做?
【问题讨论】:
-
您使用的是哪个 Web Api 版本?如果您使用的是 Web Api 2,那么您可以使用 Route 属性。
标签: c# asp.net-web-api naming-conventions asp.net-web-api-routing