当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net - using http method except actions on web api

问题描述:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: