I'm trying to create filters in my webapp controller. I want to get items by category, id or location. But they all use the same method: HTTP with an int as a parameter. What's the most elegant solution to hit only the method I want?
Here's an example of the problem. This code obviously gets the "hitting multiple endpoints" error.
[HttpGet("{id}", Name = "GetShiftById")] public ActionResult<Shift> GetShiftById(int id) { return _context.Shifts.Find(id); } [HttpGet("{locationId}", Name = "GetShiftByLocation")] public ActionResult<IEnumerable<Shift>> GetByLocation(int locationId) { return _context.Shifts .Include(s => s.Category) .Include(s => s.Location) .Where (s => s.Location.Id == locationId ) .ToList(); }
https://stackoverflow.com/questions/65894097/how-to-avoid-hitting-same-endpoint-in-asp-net-webcore January 26, 2021 at 08:00AM
没有评论:
发表评论