Registration game with Postman

Asked

Viewed 35 times

0

Hello, I’m trying to make a registration of a game but when I try to run by Postman it does not work and says that everything is null

Code

    [HttpPost]
    public async Task<IActionResult> CriarJogo([FromBody] Jogos jogo)
    {
        _contexto.Add(jogo);
        await _contexto.SaveChangesAsync();
        return RedirectToAction(nameof(Index));
    }

Postman

   {
    "Jogo":{
"JogoNome": "Forza Horizon",
"JogoDescricao": "Jogo de corrida realista.",
 "DataLancamento": "23/10/2012"
           }
   }

Model

     [Key] 
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int JogoId { get; set; }
    [Required]
    [Column(TypeName = "varchar(100)")]
    public string JogoNome { get; set; }
    [Required]
    [Column(TypeName = "text")]
    public string JogoDescricao { get; set; }
    [Required]
    [Column(TypeName = "Date")]
    public DateTime DataLancamento { get; set; }

1 answer

0

You are calling the request the wrong way, the correct would be so:

   {
       "JogoNome": "Forza Horizon",
       "JogoDescricao": "Jogo de corrida realista.",
       "DataLancamento": "23/10/2012"
   }
  • The values remain null

  • Can you complement the answer with the request you’re making on Postman? You may be forgetting some detail

  • I just redo my controller and it worked

  • I don’t know exactly what the problem was, it just worked

  • @Leonardorocha cool Leonardo, if my answer helped you, please mark it as the correct one so that the question is finalized.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.