3
I have a return that I send via Ajax that it returns in the URL as follows:
"http://localhost:11910/ProtocoloExterno/Inserir?itensContrato[0][id]=4&itensContrato[0][valorUsado]=150000,00&itensContrato[1][id]=9&itensContrato[1][valorUsado]=10050,00&contrato=4100001124&codigoParceiro=7900325&nomeParceiro=ORANGE COTE D%23IVOIRE S.A.&areaReclamacao=&codigoPatrimonial=5411050&operadora=Móvel&statusObra=&nFRN=&endereco=Rua Ursulina de Melo&estado=AM&cidade=78&descItem=desc&icms=15100,00&ipi=410,00&contaContabil=Capital não chamado&ordemInterna=Rua Ursulina de Melo&quantidade=1&valorUnitario=160050,00&valorTotal=160050,00&numeroPedido=11000110&itemPedido=10&observacao="
When I put Request.QueryString["endereco"];
for example, got cute, the biggest difficulty is to get the data that send from an array via ajax.
Excerpt that I send via javascript
$(document).on('click', "#btnSalvar", function () {
var erros = 0;
$("div").find('*').each(function () {
var classe = $(this).attr("class");
if (classe !== undefined) {
var numItems = $('.has-error').length;
if (numItems > 0) {
return false;
}
else {
//debugger;
itensContrato = [];
$("input:checked").each(function () {
var id = $(this).data("id");
var valorUsado = $(".txt" + id).val();
itensContrato.push({ id: id, valorUsado: valorUsado })
});
debugger;
$.ajax({
type: 'GET',
url: 'Inserir',
dataType: 'JSON',
data: {
itensContrato: itensContrato,
contrato: $("#cmbContrato").val(),
codigoParceiro: $("#lblCodigoParceiro").html(),
nomeParceiro: $("#lblNomeParceiro").html(),
tipoContrato: $("#cmbTipoContrato").val(),
areaReclamacao: $("#lblAreaReclamacao").html(),
codigoPatrimonial: $("#txtCodigoPatrimonial").val(),
operadora: $("#cmbOperadora").val(),
statusObra: $("#cmbStatusObra").val(),
nFRN: $("#txtNFnr").val(),
endereco: $("#txtEndereço").val(),
estado: $("#cmbEstado").val(),
cidade: $("#cmbCidade").val(),
descItem: $("#txtDescricaoItem").val(),
icms: $("#txtICMS").val(),
ipi: $("#txtIPI").val(),
contaContabil: $("#lblContaContabil").html(),
ordemInterna: $("#txtOrdemInterna").val(),
quantidade: $("#txtQuantidade").val(),
valorUnitario: $("#txtValorUnitario").val(),
valorTotal: $("#txtValorTotal").val(),
numeroPedido: $("#txtNumeroPedido").val(),
itemPedido: $("#txtItemPedido").val(),
observacao: $("#txtObservacao").val()
}
});
return false;
}
}
});
});
If I indicate a parameter as itensContract[0][id] it can get the right value, but since I don’t know how many itensContract has, I wanted to go through the url in such a way that I found the amount of itensContract[pos][id] and itensContract[pos][useUsed]
It needs to be via
GET
? If Asp.MVC, you can use instead ofRequest.QueryString
, parameters within the method called in the controller. Example:public ActionResult NomeDoMetodoNoController (string [] itensContrato, string contrato, string codigoParceiro, string nomeParceiro, ...) { }
. It is worth noting that the types of parameter go according to the parse made.– Daniel Nicodemos
@Danielnicodemos but my real difficulty is to catch them via Request.Querystring
– gabrielfalieri
could post your controller?
– Daniel Nicodemos
I’ll take the risk of being ridiculed, but
itensContrato[0][id]=4
does not seem to me an acceptable syntax for querystring. If you want to pass an array of compound objects, I suggest you do via POST– Eric Wu
@Danielnicodemos sorry the years of delay, I just need to know how to get this itensContract syntax
– gabrielfalieri
@gabrielfalieri How are you doing with the
QueryString
What do you get? Are you turning into a class or are you picking up values on the nail so to speak?– rodrigogq
@rodrigogq
– gabrielfalieri