I'm not sure what is wrong with my route. the breakpoint is not firing when I try to access the route.
here is the source message from googles advanced rest client
POST /api/menu HTTP/1.1
HOST: localhost:6223
content-type: application/json
content-length: 34
{ "app_id": 99999, "user_type": 2}
[Route("api/[controller]")]
public class MenuController : Controller
{
private MenuRepo xMenuRepo;
public MenuController(IOptions<SqlConnectionStringsList> iopt)
{
xMenuRepo = new MenuRepo(iopt);
}
[HttpPost]
public IEnumerable<Menu> GetMenuItems([FromBody] MenuQuery menuq)
{
List<Menu> xMenuList = new List<Menu>();
xMenuList = xMenuRepo.GetMenuItems(menuq.app_id, menuq.user_type);
return xMenuList;
}
}
public class MenuQuery
{
public int app_id { get; set; }
public int user_type { get; set; }
}
GetMenuItems
Route for action is missing
Routing to Controller Actions: Attribute Routing
MVC applications can mix the use of conventional routing and attribute routing. It’s typical to use conventional routes for controllers serving HTML pages for browsers, and attribute routing for controllers serving REST APIs.
Actions are either conventionally routed or attribute routed. Placing a route on the controller or the action makes it attribute routed. Actions that define attribute routes cannot be reached through the conventional routes and vice-versa. Any route attribute on the controller makes all actions in the controller attribute routed.
[Route("api/[controller]")]
public class MenuController : Controller
{
private MenuRepo xMenuRepo;
public MenuController(IOptions<SqlConnectionStringsList> iopt)
{
xMenuRepo = new MenuRepo(iopt);
}
//POST api/menu
[HttpPost("")]
public IEnumerable<Menu> GetMenuItems([FromBody] MenuQuery menuq)
{
List<Menu> xMenuList = new List<Menu>();
xMenuList = xMenuRepo.GetMenuItems(menuq.app_id, menuq.user_type);
return xMenuList;
}
}