问题描述:

asp.net web api controller has standart http method support. GET, POST, DELETE, PATCH. So controller has standart methods of http. For example I have a ProductController. I can get products, delete, create and update.

If I need best seller products, I need new GET method. In this stuation, controller gives error "Multiple actions were found that match the request: Get"

Should I create a new controller for these operations or use in same controller?

网友答案:

You can do that by modifying the routing, following is default routing (App_start -> webApiConfig.cs)

config.Routes.MapHttpRoute( 
name: "API Default", 
routeTemplate: "api/{controller}/{id}", 
defaults: new { id = RouteParameter.Optional } 

);

You need to modify it to:

config.Routes.MapHttpRoute( 
   name: "ActionApi", 
   routeTemplate: "api/{controller}/{action}/{id}", 
   defaults: new { id = RouteParameter.Optional } 
);

Another answer with similar problem

Hope that helps

相关阅读:
Top