How to pass a JSON Object to a method in webservice?

2

I'm trying to pass a JSON Object to a method in my controller and I'm not getting it, the problem is that the email field always returns null.

How to do this?

I'm trying like this.

JSON Object

{"UsuarioJsonModel": {"email":"[email protected]", "senha":"xxxxxx"}}

Model

public class UsuarioJsonModel 
{

    public long id                  { get; set; }         
    public String nome              {   get;set;}            
    public String email             {get;set;}    
    public String senha             {get;set;}   
    public int status               { get; set; } //1 ativo, 2 inativo, 0 aguardando
    public int tipo                 { get; set; } //1 painel, 2 aplicativos
    public String imagem            { get; set; }
    public int loginBy              { get; set; } //0 app, 1 facebook
    public UsuarioJsonModel() { }

}

Method that receives JSON Object

[WebMethod]
[HttpPost]
public JsonResult doLoginApp(UsuarioJsonModel model)
{ 
    jsonResposta.Add("status", "1");
    jsonResposta.Add("email", model.email);
    return Json(jsonResposta);
}
    
asked by anonymous 10.11.2016 / 19:07

1 answer

2

You need to pass an object that has the properties defined in the model. In the current way, an object with the UsuarioJsonModel property is being passed and this property is the object you need.

Just change your JSON to

{ "email":"[email protected]", "senha":"xxxxxx" }
    
10.11.2016 / 19:39