我有一个类似于 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 报告以下请求(不包括 User Agent String 等无关位)
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我的控制器操作是
[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注意缺少查询"
更多推荐
FromBody 未绑定字符串参数
发布评论