MVC4 webapi 베타를 RC로 업데이트 한 이후로 문제에 대한 도움을 요청하는 몇 가지 이전 질문을했습니다. 나는 지금 대부분의 것을 가지고있다. 그러나 여기에서는 내가 이유를 아직 이해할 수 없다.POST를하는 간단한 컨트롤러를 찾지 못했습니다.
이 간단한 컨트롤러에는 POST를 허용하는 컨트롤러와 GET을 허용하는 컨트롤러가 있습니다. HTML 폼에서 요청을 보내 실행하려고하면 POST 컨트롤러가 다음 오류를 반환하는 동안 GET 컨트롤러 만 발견됩니다.
{
"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'."
}
왜 POST 컨트롤러를 찾을 수 없습니까? 당신이 "간단한"값을 게시 할 때
컨트롤러
public class PlayController : ApiController
{
[HttpPost] // not found
public string Test(string output)
{
return output;
}
[HttpGet] // works
public string Test2(string output)
{
return output;
}
}
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>
3 년 후 차임을 할 수 있으면 감사합니다 !! 이것은 방금 몇 시간을 소비 한 문제를 해결했습니다. 이것은 정확히 SO가하는 모든 것입니다. –
webApiConfig.cs와 컨트롤러의 프로 시저 사이에 매개 변수 이름 불일치가있을 때 동일한 오류가 발생했습니다. –