How to force web API to recognise querystring parameter

六月ゝ 毕业季﹏ 提交于 2019-12-04 00:09:56

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.

Another option is to implement a custom type provider. This allows control over the representation in the query string, and means you don't have to add the [FromUri] attribute to your action methods. This makes sense if you have widespread reuse of a complex parameter type, or need a custom representation.

A good example of this is given in this blog post where a location with latitude and longitude is implemented using both techniques.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!