0
votes

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?

1
Provide minimal reproducible example that reproduces problem. That said no need for new controller per say. update routing to be able to differentiate the two actions either via convention-based routing or attribute routing.Nkosi

1 Answers

0
votes

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