Since after a few days I am trying to create my own api web controller. Duo for other conventions I need to use a mail request to create an object. To get specific, Im has this controller with this action:
public class ReservationController : ApiController { [HttpPost] public void Create(int roomId, DateTime arrivalDate) {
This code does not work when I run the mail request, I get exception 404, something like this:
No actions were found on the Some controller that match the query.
The reason for this is that simple types are read from the query string, complex types from the body, according to this aricle . The web api uses parameters to match the action with the request and therefore cannot match my action with the request.
I know that I can use the [frombody] tag, but you can only apply it to one parameter, and I have 2. I also know that I can create a wrapper object that has both parameters, but I'm not wanting use wrappers for all my calls.
Therefore, I know that I can get around this with these methods. I also think that this is due to the fact that the body of the mail request can be read only once. But my real question is:
Why is the type of the parameter determined by the source of the parameter, and not its availability, especially if the agreements indicate what you should do, for example, a request to create to create? In MVC this is so, why is it not in a web api?
Yours faithfully,
Bhd
FINAL UPDATE As I get some advances, probably more people are facing the same issue. As a result, this comes to the following: Web-Api! = MVC. This is simply not the same, and the web api team made various design decisions than the mvc team, I think.