AttributeRouting icon indicating copy to clipboard operation
AttributeRouting copied to clipboard

Optional parameter

Open smolesen opened this issue 11 years ago • 1 comments

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

smolesen avatar Mar 22 '13 13:03 smolesen

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.

mccalltd avatar Apr 19 '13 03:04 mccalltd