I am trying to create a MVC WebAPI controller, which takes in an id, which it creates a record with in the database and then returns. However, I keep getting an error.
In my testAPI controller I have:
[HttpPost]
public HttpResponseMessage OpenSession(int id)
{
//Logic of post in here never gets hit
}
However when I try and post to the API I get the following response:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:54388/api/testAPI/OpenSession/'.","MessageDetail":"No action was found on the controller 'testAPI' that matches the request."}
I have changed my routing to:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/"
);
I am trying to post to: http://localhost:54388/api/testAPI/OpenSession/
with the value id in the payload. However I think it is expecting it in the URL - can someone please point out where I am going wrong.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…