Ho fatto qualche domanda precedente per chiedere l'aiuto con i problemi da quando ho aggiornato MVC4 webapi beta in RC. Ora mi sono impegnato di più, ma ecco uno che non riesco ancora a capire.Il controller semplice che accetta POST non viene trovato
Per questo semplice controller ne ho uno che accetta un POST e uno che accetta GET. Quando provo a eseguire quelli inviando richiesta da un modulo HTML, viene trovato solo il controller GET mentre il POST mi restituirà il seguente errore.
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost/webapi/api/play/test'.",
"MessageDetail": "No action was found on the controller 'Play' that matches the name 'test'."
}
Perché il controller POST non è stato trovato?
Controller
public class PlayController : ApiController
{
[HttpPost] // not found
public string Test(string output)
{
return output;
}
[HttpGet] // works
public string Test2(string output)
{
return output;
}
}
modulo HTML
<form action="http://localhost/webapi/api/play/test" method="post">
<input type="text" name="output" />
<input type="submit" name="submit" />
</form>
<form action="http://localhost/webapi/api/play/test2" method="get">
<input type="text" name="output" />
<input type="submit" name="submit" />
</form>
Se riesco a suonare in 3 anni dopo, grazie !! Questo ha risolto un problema su cui ho appena passato ore. Questo è esattamente ciò che SO è tutto. –
Ho ricevuto lo stesso errore quando avevo una mancata corrispondenza del nome parametro tra webApiConfig.cs e la procedura nel controller. –