简体   繁体   中英

How to send Json in Post request with Web Api

I have this method receiving a post request and i'm not able to send a json

[HttpPost]
[Route("SalvarCliente")]
public HttpResponseMessage SalvarCliente(ClienteVM cliente)
{
    try
    {
        _clienteService.SalvarCliente(cliente);
        return new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = MessageJson("Cliente cadastrado com sucesso")
        };
    }
    catch (Exception ex)
    {
        return new HttpResponseMessage(HttpStatusCode.BadRequest);
    }
}

My class ClienteVM:

  public class ClienteVM
   {
      public int Id { get; set; }

     [Required]
     public string  Nome { get; set; }

     [Required]
     public DateTime DataNascimento { get; set; }

     [Required]
     public DateTime DataInclusao { get; set; }

     public List<EnderecoVM> enderecos { get; set; }

     [Required]
     public byte Status { get; set; }

     }

which correct model of jason do i have to send? I'm testing by the postman you don't need to put the List EnderecoVm for a while.

I Try:

在此处输入图片说明

Your postman should be like below: 在此处输入图片说明

Result: 在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM