Multiple optional parameters web api attribute routing

前端 未结 2 1534
余生分开走
余生分开走 2021-01-19 12:28

Hi guys i am new to attribute routing and not sure if this is even possible.

What i have is an attribute route which works fine like this

[HttpGet]
         


        
2条回答
  •  被撕碎了的回忆
    2021-01-19 12:47

    {flag:int=3?} is the problem. it is either optional {flag:int?} with the default value in the action or {flag:int=3}.

    [HttpGet]
    Route("GetIssuesByFlag/{flag:int=3}/{categoryId:int?}/{tagIds?}")]
    public IEnumerable GetIssuesByFlag(int flag , int? categoryId = null, int?[] tagIds = null)
    

    You currently have 3 optional parameters. when you have just the 1 value routing table wont know which optional parameter you are referring to, hence the 404

提交回复
热议问题