C#
C#

help

Root Question Message

TotechsStrypper
TotechsStrypper8/17/2022
[ASP.NET Controller] No route matches the supplied values

I'm trying to redirect my call to get the animal information from the create action method using this
return CreatedAtAction(nameof(GetById), new { Id = animal.Id }, _mapper.Map<AnimalDTO>(animal));

And this is my GetById Action method
[HttpGet("{animalId}")]
        public async Task<IActionResult> GetById(int animalId, CancellationToken cancellationToken = default)
        {
            var animal = await _animalRepository.FindByIdAsync(animalId, cancellationToken);
            return animal != null ? Ok(_mapper.Map<AnimalDTO>(animal)) : NotFound("Unable to find the requested animal"); 
        }
Angius
Angius8/17/2022
The route param is animalId not Id
TotechsStrypper
TotechsStrypper8/17/2022
thanks
TotechsStrypper
TotechsStrypper8/17/2022
It doesnt trigger the breakpoint that set in GetById method ?
Angius
Angius8/17/2022
IIRC it doesn't actually call that action, because why would it? It just returns the 201 Created response and sets the Location header to the route from which you can fetch that resource
Angius
Angius8/17/2022
That's why it needs the action name and the parameters, to construct that route
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy