我正在尝试创建一个路由,该路由将由我的每个控制器的 GetAll 方法与分页的默认 Get 方法处理,以便 url 如下所示:“api/{controller}/all”
public class MyController {
public IEnumerable<MyModel> GetAll() {
...
}
public IEnumerable<MyModel> Get(int page = 0, int pageSize = 50) {
...
}
}
public class MyOtherController {
public IEnumerable<MyOtherModel> GetAll() {
...
}
public IEnumerable<MyOtherModel> Get(int page = 0, int pageSize = 50) {
...
}
}
我的路线目前看起来像这样:
config.Routes.MapHttpRoute(
name: ControllerOnlyRoute,
routeTemplate: "api/{controller}"
);
config.Routes.MapHttpRoute(
name: ControllerAndIdRoute,
routeTemplate: "api/{controller}/{id}",
defaults: null
);
config.Routes.MapHttpRoute(
name: ControllerActionRoute,
routeTemplate: "api/{controller}/{action}"
);
我不确定如何为将路由到 GetAll 方法的每个控制器创建路由?