I have a Web API Controller with a method called GetHeroes()
and it doesn't get called by the front end. I can get a simple Get()
method to work but there doesn't seem to be a way to name methods and have these methods called.
CharactersController.cs
[Route("api/{controller}/{action}")]
public class CharactersController : Controller
{
private readonly ICharacterRepository _characterRepository;
public CharactersController(ICharacterRepository characterRepository)
{
_characterRepository = characterRepository;
}
[HttpGet]
public IEnumerable<Character> GetHeroes()
{
return _characterRepository.ListAll().OrderBy(x => x.Name);
}
}
data.service.ts
getItems() {
this.http.get('api/characters/getheroes').map((res: Response) => res.json()).subscribe(items => {
this._collectionObserver.next(items);
});
}