I have the following code
[HttpGet]
[Route("publish/{id}")]
public IHttpActionResult B(string id, string publishid=null) { ... }
So as far as I understood,
~/..../publish/1?publishid=12
~/..../publish?id=1&publishid=12
Should work and bind both parameters but it won't work on the second case. In the first case, publishid will not be bound.
So I do not understand why this is not working. Any idea why it is in this way?
The second case will not work because id
is a required variable in the route template publish/{id}
. In Web API first route template matching happens and then the action selection process.
other cases:
publish/1
- will not work as action B
is saying that publishid is required. To prevent this you can change the signature of action to be something like B(string id, string publishid=null)
and only id
is boundpublish/1?publishid=10
- works as expected where both are bound.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With