Query string not working while using attribute routing

后端 未结 8 2274
無奈伤痛
無奈伤痛 2020-11-27 12:52

I\'m using System.Web.Http.RouteAttribute and System.Web.Http.RoutePrefixAttribute to enable cleaner URLs for my Web API 2 application. For most of

8条回答
  •  难免孤独
    2020-11-27 13:37

    I was facing the same issue of 'How to include search parameters as a query string?', while I was trying to build a web api for my current project. After googling, the following is working fine for me:

    Api controller action:

    [HttpGet, Route("search/{categoryid=categoryid}/{ordercode=ordercode}")]
    
    public Task GetProducts(string categoryId, string orderCode)
    {
    
    }
    

    The url I tried through postman:

    http://localhost/PD/search?categoryid=all-products&ordercode=star-1932
    
    http://localhost/PD is my hosted api
    

提交回复
热议问题