我有类似ASP.NET MVC 4 RC的Web API参数绑定问题的,但我想通过[FromBody]属性来解决这个问题。
I have an issue similar to ASP.NET MVC 4 RC Web API Parameter Binding Issue, but I'm trying to solve it by using the [FromBody] attribute.
提琴手报告以下要求(不包括不相关的位像用户代理字符串)
Fiddler reports the following request (excluding irrelevant bits like User Agent String)
PUT localhost:82/api/account/shoppinglistitems HTTP/1.1 Host: localhost:82 Connection: keep-alive Content-Length: 11 Origin: localhost:3000 Content-Type: application/x-www-form-urlencoded Accept: application/json, text/javascript, */*; q=0.01 query=apple
我的控制器动作
My controller action is
[HttpPut] public ShoppingListItemWebModel CreateShoppingListItem([FromBody]string query) { // query is null }
我可以换一个复杂类型的参数,但是,似乎是一个黑客来解决该问题。或者,我可以把在URI查询,但是,这并不符合API的其余部分的图案。是否有可能做这种方式?如果是这样,哪里是我的错?
I could wrap the parameter in a complex type, but that seems like a hack to fix the issue. Or I could put the query in the URI, but that doesn't fit the pattern of the rest of the API. Is it possible to do it this way? If so, where is my mistake?
推荐答案更改您的要求为
PUT localhost:82/api/account/shoppinglistitems HTTP/1.1 Host: localhost:82 Connection: keep-alive Content-Length: 11 Origin: localhost:3000 Content-Type: application/x-www-form-urlencoded Accept: application/json, text/javascript, */*; q=0.01 =apple
注意缺少查询
notice the lack of "query"
更多推荐
FromBody没有约束力字符串参数
发布评论