How to force web API to recognise querystring parameter

前端 未结 2 1781
半阙折子戏
半阙折子戏 2021-02-19 11:00

ASP.NET MVC4 Web API v1 controller is defined below. It should accept 1 or 2 query string parametrs.

However ko parameter is always null if method is called. Request is

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-19 11:35

    Complex types are fetched from the body of a request, but you can change this default behaviour like this :

    public HttpResponseMessage Get([FromUri]CustomersSearchViewModel ko)
    

    Your querystring should contain parameters named like your model properties, otherwise the binding won't work.

提交回复
热议问题