Error sending a route to the same api / Controller / Action in a WebApi

1

I'm having the following error, I perform the following operation:

        // POST: api/Funcionario/AddFuncionario
    [HttpPost("AddFuncionario")]
    public IActionResult AddFuncionario([FromBody] Funcionario Func)
    {
        if(Func == null)
        {
            return BadRequest();
        }

        funcionarioRepository.AddFuncionario(Func);
        return CreatedAtRoute("BuscarPorId/{id}", new { id = Func.Id }, Func);

    }

Follow my Action from Api:

        [HttpGet("BuscarPorId/{id}")]
    public IActionResult BuscarPorId(int id)
    {
        var item = funcionarioRepository.BuscarPorFuncionario(id);
        return new ObjectResult(item);
    }
    
asked by anonymous 13.11.2017 / 16:14

1 answer

0

You need to name the route, CreatedAtRoute search for a route by name and not the template ".

>
[HttpGet("BuscarPorId/{id}", Name = "NomeDaRota")]
public IActionResult BuscarPorId(int id) { }

public IActionResult AddFuncionario([FromBody] Funcionario Func)
{
    // (...)
    return CreatedAtRoute("NomeDaRota", new { id = Func.Id }, Func);
}
    
13.11.2017 / 16:20