How to add custom methods to ASP.NET WebAPI controller?

后端 未结 4 1410
悲&欢浪女
悲&欢浪女 2020-12-14 01:52

In ASP.NET MVC WebAPI project by default we have created following controller

 public class ValuesController : ApiController
    {
        /         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-14 02:11

    You could use attribute routing:

    [Route("customers/{customerId}/orders")]
    public IEnumerable GetOrdersByCustomer(int customerId) { ... }
    

    Some documentation to get you started:

    http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

提交回复
热议问题