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

后端 未结 6 1410
南旧
南旧 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:47

    You can have a dispatcher endpoint that will get the calls from both endpoints and will call the right based on parameters. (It will works fine if their are in same controller).

    Example:

    // api/menus/{menuId}/menuitems
    [HttpGet("{menuId}/menuitems")]
    public IActionResult GetAllMenuItemsByMenuId(int menuId, int? userId)
    {            
        if(userId.HasValue)
           return GetMenuItemsByMenuAndUser(menuId, userId)
    .... original logic
    }
    
    public IActionResult GetMenuItemsByMenuAndUser(int menuId, int userId)
    {
        ...
    }
    

提交回复
热议问题