Frage

I'm using WebApi and attribute routing.

I have a customer controller that has a method to get all the animals for that customer. This method & route work great. However, I also want a method that just returns a list of all the customers, and I can't get that one to work.

Here is my controller:

[RoutePrefix("api/customer")]
    public class CustomerController : ApiController
    {
        [HttpGet("{customerId}/animals")]
        public PagedHorse Get(int customerId)
        {
                Console.WriteLine("Get");
        }

        [HttpGet("")]
        public PagedCustomer List()
        {
                Console.WriteLine("List");
        }
    }

If I change the List route to be "{customerId}/List" and ignore the parameter passed in, it works. What am I doing wrong with these routes? I'd really like to just have api/customer return a list of all customers.

War es hilfreich?

Lösung

It appears there was some amount of interference between the Hot Towel SPA project type and my project. I didn't start from scratch with Hot Towel, but added it to an existing project, so I believe there were some routing issues.

I deleted the HotTowel specific Configs (e.g. HotTowelRouteConfig) because everything that was done there I was already doing in my ASAX file.

After that everything worked fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top