Ho un problema simile a ASP.NET MVC 4 RC Web API Parameter Binding Issue, ma sto cercando di risolverlo utilizzando l'attributo [FromBody].FromBody not binding string parameter
Fiddler riporta la seguente richiesta (esclusi i bit irrilevanti come User Agent String)
PUT http://localhost:82/api/account/shoppinglistitems HTTP/1.1
Host: localhost:82
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:3000
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
query=apple
La mia azione del controller è
[HttpPut]
public ShoppingListItemWebModel CreateShoppingListItem([FromBody]string query) {
// query is null
}
ho potuto avvolgere il parametro in un tipo complesso, ma che sembra un trucco per risolvere il problema. Oppure potrei inserire la query nell'URI, ma ciò non si adatta allo schema del resto dell'API. È possibile farlo in questo modo? Se è così, dov'è il mio errore?
Il titolo dice POST, ma la domanda dice PUT. Solo un po 'fuorviante. – vbullinger
Domanda correlata per Asp.Net Core https://stackoverflow.com/questions/31952002/asp-net-core-mvc-how-to-get-raw-json-bound-to-a-string-without-a- digitare –