In my Method the param always comes null, but any other request type (get, put, delete) is doesn't happen.
This problem just happens in request type POST.
This is my Method
[HttpPost]
public IActionResult Post([FromBody]Dificuldade value)
{
if (value == null)
{
return BadRequest();
}
return CreatedAtRoute("Get", new { id = value.Id }, value);
}
This is my Model
public class Dificuldade
{
public int Id { get; set; }
//Pessoa pela qual passa difilcudade ou relatou o problema
public string NomePessoa { get; set; }
public string Latitude { get; set; }
public string Longetude { get; set; }
//Descricao da difilcudade
public string Descricao { get; set; }
public DateTime DataHoraRegistrado { get; set; }
public DateTime DataHoraSolucionado { get; set; }
public bool Solucionado { get; set; }
public int BairroId { get; set; }
public Bairro Bairro { get; set; }
public int CategoriaId { get; set; }
public Categoria Categoria { get; set; }
//Usuario no qual fez o registro
public int UsuarioId { get; set; }
public Usuario Usuario { get; set; }
}
And this is my request Postman
Your action accepts an individual object. You are sending an array of them.
So you would need to send something like:
{ "id":1, "namePessoa": "Something"... }
Instead of:
[{ "id":1, "namePessoa": "Something"... }]
If instead you wanted to receive a set of objects, you need to change your controller action like this:
public IActionResult Post([FromBody]List<Dificuldade> value)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.