Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used this tutorial to start with core 2.2 Tutorial: Create a web API with ASP.NET Core MVC | Microsoft Docs[^], filed off the serial numbers and changed the colour but the same style.

All went well until I wanted to get a filtered selection so I need a second (and third) GET. Using Postman I get a duplicate GET error with
https://localhost:44334/api/userdetails?FleetID=1

There is no routing in the Startup.cs

What I have tried:

Controller starts with
[Route("api/[controller]")]
[ApiController]
public class UserDetailsController : ControllerBase
    {
		DAL.UserDetails dsUserDetails = new UserDetails();

		[HttpGet]
		public ActionResult<IEnumerable<UserDetailsDB>> GetUsers()
		{
			IEnumerable<UserDetailsDB> lResult = dsUserDetails.UserDetailsList();
			return lResult.ToList();
		}


Second GET with additional filter - what is the decoration for this or the calling syntax for the GET
[HttpGet]
public ActionResult<IEnumerable<UserDetailsDB>> GetUserForFleet([FromQuery] int FleetID)
{
  IEnumerable<UserDetailsDB> lResult = dsUserDetails.UserDetailsForFleet(FleetID);
  return lResult.ToList();
}
Posted
Updated 7-Mar-19 20:46pm

1 solution

Put the route name in the decorator:

[HttpGet("GetUserForFleet")]

So you can call:

https://localhost:44334/api/UserDetails/GetUserForFleet?FleetID=1
 
Share this answer
 
Comments
Mycroft Holmes 8-Mar-19 17:13pm    
Thanks - the last hurdle to getting my POC ready except I need to secure the API now [chuckle]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900