Open View with Parameters [duplicate]

4

I have this script:

$('#Musico').change(function () {
    var id = $(Musico).val();
    var url = '@Url.Action("Votar","Chamada")';
    var tipo = 1;

    $(function ChamaVotar() {
        $.post(url, { id: id, tipo: tipo });
    });//Function ChamaVotar

});//musico change

And this 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);
    }
    else//Local
    {
        var chamadaMusicas = db.ChamadaMusicas.Include(c => c.Chamada).Include(c => c.Musica).Where(c => c.Chamada.LocalID.Equals(id)).Where(i => i.Chamada.Ativa.Equals(true)).ToList();
        return View(chamadaMusicas);
    }
}

I need to, when I pass my parameters to the controller, the view is opened. But it is not opening ... The controller receives the information but does not open the page. What solution to this?

    
asked by anonymous 25.11.2016 / 00:31

2 answers

4

The solution I found to solve my problem was as follows, where id and tipo were passed through parameters via URL. To open the window I used window.location.replace (which opens in the same window without opening a new tab).

$('#Musico').change(function () {
    var id = $(Evento).val();
    var url = '@Url.Action("Votar", "Chamada")';
    var tipo = 2;
    window.location.replace(url + '?id=' + id + '&tipo=' + tipo);

});
    
25.11.2016 / 12:33
4

Try to build the url this way:

var url = '@Url.Action("Action", "Controller")' + '?id=' + id + '&tipo=' + tipo;

$.ajax({
    type: 'GET',
    url: url,
    dataType: 'html',
    success: function (data) {
         // faz alguma coisa
    }
});

Note: I am editing the answer because I was wrong.

    
25.11.2016 / 12:01