0

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
    Commented Dec 5, 2016 at 10:17

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.