8
I have the following code in js
function consultaSolicitacao() {
id = getVar("id");
serviceURL = "/Solicitacao/ConsultaSolicitacao";
$.get(serviceURL, null, function (data) {
var aux = data.length;
var tblText = '';
for (var i = 0; i < aux; i++) {
var tmpArgs = data[i].id + ",'" + data[i].assunto
+ "','" + data[i].mensagem + "','" + data[i].endereco + "','" + data[i].anexo + "'";
var id = data[i].id;
tblText += '<div id="Solicitacoes"><div>';
tblText += '<span id="idSolicitacao">' + data[i].id + '</span>';
tblText += '</div></div></a>';
}
document.getElementById("solicitacaoID").innerHTML = tblText;
});
}
I need to pass the value of my id variable to the controller:
public ActionResult ConsultaSolicitacao(int id)
{
var x = Teste.ConultaSolicitacao(id);
return new JsonResult()
{
Data = x, JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
But I don’t know how to send the js variable to the controller. The controller is already waiting but I don’t know how to do it.
Tried to
var serviceURL = "/Solicitacao/ConsultaSolicitacao/" + id;
?– bfavaretto
This way it passes the link and not by parameter, hence the error. The link is http://localhost:18376/Request/Query
– Vinicius VAz
One bar was missing before the
2
, read again my example.– bfavaretto
Thank you very much
– Vinicius VAz
What if I need to pass 2 variables? I tried so but this giving error.
var serviceURL = "/Solicitacao/UpdateDepartamentos/" + id_Departamento + id_Solicitacao;
and so toovar serviceURL = "/Solicitacao/UpdateDepartamentos/" + id_Departamento, id_Solicitacao;
– Vinicius VAz