AttributeRouting
AttributeRouting copied to clipboard
Optional parameter
Given the following controller:
[RoutePrefix("product")]
public class ValuesController : ApiController
{
[GET("?{number:int=0}"), HttpGet]
public void GetByName(int number=0)
{
...
}
}
I would have expected to be able to reach it using:
~/product
however is seems like I have to add the Optional parameter for this to work:
[GET("?{number:int=0?}"), HttpGet]
Shouldn't it just be implicit, that a parameter with a default value is optional??
/Søren
Query params don't work in web api web host, FYI. But if you're in self-host, should work (I think). The default and optional param together is nonsense, as you correctly surmised, and should trigger an "invalid syntax" exception or something.