I try to trigger a specific method (the second one) in HeroesController class:
[HttpGet]
public IEnumerable<Hero> Get()
{
return Heroes;
}
[HttpGet("/name={term}")]
public IEnumerable<Hero> Get(string term)
{
return Heroes;
}
After calling this URL:
https://localhost:44375/heroes/?name=Spider
The first method is triggered, not the second. Why is that so? How to trigger the second one which receives term parameter?
https://localhost:44375/heroes/name=Spider- but using the=in the pattern is unusual.Getmethod (as you said, it's invoked). The url you want has a part calledquery string. TheGetmethod then should be likeGet(string name). The secondGetmakes no sense, just remove the[HttpGet("/name={term}")]