[英]Can ngResource pass nested object into GET query?
I am using ngResource to communicate with my Web API. 我正在使用ngResource与我的Web API通信。 I want to send a search request to my WebAPI controller but the object is not flat:
我想向我的WebAPI控制器发送搜索请求,但是对象不是平面的:
var searchRequest = {
query: "hotel",
page: 1,
price:
{
min: 1000,
max: 2500
}
}
And my controller takes a SearchRequest parameter with the same structure as sent object so the request should look like 并且我的控制器采用与发送对象具有相同结构的SearchRequest参数,因此请求应类似于
http://localhost/api/search?query=hotel&page=1&price.min=1000&price.max=2500
However, ngResource $resource.query(searchRequest)
is sending this: 但是,ngResource
$resource.query(searchRequest)
发送此消息:
http://localhost/api/search?query=hotel&page=1price=%7B%22min%22:1000,%22max%22:2500%7D
If it was me I would change this to use an OData attributed endpoint that returns an IQueryable. 如果是我,我将其更改为使用返回IQueryable的OData属性终结点。 Then use breeze.js on the frontend to generate the queries.
然后在前端使用breeze.js生成查询。 Have a look at these:
看看这些:
https://ovaismehboob.wordpress.com/2014/01/18/adding-queryable-support-to-asp-net-web-api-controller-action-methods/ https://ovaismehboob.wordpress.com/2014/01/18/adding-queryable-support-to-asp-net-web-api-controller-action-methods/
http://breeze.github.io/doc-js/server-odata.html http://breeze.github.io/doc-js/server-odata.html
I could be wrong but I don't think this will work with nested queries. 我可能是错的,但我认为这不适用于嵌套查询。 Another solution might be to flatten the query and then use a linq projection or automapper projection to query the data source but that would depend on what you linq provider can handle
另一个解决方案可能是先平整查询,然后使用linq投影或automapper投影来查询数据源,但这取决于linq提供程序可以处理的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.