How to call a View passing parameters through json

3

I have this code that passes parameters to my controller:

var id = $(Musico).val();
var url = '@Url.Action("Votar","Chamada")';
var tipo = 1;
$.ajax({
    url: url,
    data: {
         id:id, tipo:tipo
    }
});

My controller:

    public ActionResult Votar(int id, int tipo)
    {
        if (tipo == 1)//Tipo Musico
        {
            var chamadaMusicas = db.ChamadaMusicas.Include(c => c.Chamada).Include(c => c.Musica).Where(c => c.Chamada.PessoaID.Equals(id)).Where(i => i.Chamada.Ativa.Equals(true)).ToList();
            return View(chamadaMusicas);//Fábio Souza);
        }
        else//Local
        {
            var chamadaMusicas = db.ChamadaMusicas.Include(c => c.Chamada).Include(c => c.Musica).Where(c => c.Chamada.LocalID.Equals(id));
            return View(chamadaMusicas.ToList().Where(i => i.Chamada.Ativa.Equals(true)));//Fábio Souza);
        }
    }

until the controller is receiving all the information, but the view does not open. What would you have to do for the Vote view to open?

    
asked by anonymous 25.11.2016 / 02:55

1 answer

5

You are not handling the Ajax callback.

You have to deal in Success , get the result and insert somewhere.

        $.ajax({
        url: url,
        type: "GET",
        success: function (result) {
            $('#resultado').html(result);
        },
        error: function (x, m, s) {
            if (x.status == 403) {
                alert(m, x.statusText);
            } else {
                alert(x.responseText);
            }
        }            
    });
    
25.11.2016 / 11:25