How do I resolve the issue the request matched multiple endpoints in .Net Core Web Api

后端 未结 6 1441
南旧
南旧 2020-12-31 03:08

I notice that there are a bunch of similar questions out there about this topic.

I\'m getting this error when calling any of the methods below.

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 03:50

    Action routes need to be unique to avoid route conflicts.

    If willing to change the URL consider including the userId in the route

    // api/menus/{menuId}/menuitems
    [HttpGet("{menuId:int}/menuitems")]
    public IActionResult GetAllMenuItemsByMenuId(int menuId)  
        //....
    }
    
    // api/menus/{menuId}/menuitems/{userId}
    [HttpGet("{menuId:int}/menuitems/{userId:int}")]
    public IActionResult GetMenuItemsByMenuAndUser(int menuId, int userId) {
        //...
    }
    

    ##Reference Routing to controller actions in ASP.NET Core

    ##Reference Routing in ASP.NET Core

提交回复
热议问题