Created
October 25, 2017 18:37
-
-
Save zaidepilef/c4415c404d73baddf42b7efa7f36cf24 to your computer and use it in GitHub Desktop.
Ajax json ASP.NET MVC y poblar una tablagrilla
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!---ajax para traer listado bitacora--> | |
<script type="text/javascript"> | |
$(function () { | |
$("#btnGet").click(function () { | |
var NumeroCotizacion = $("#NumeroCotizacion").val(); | |
var NumeroPoliza = $("#NumeroPoliza").val(); | |
var FechaInicio = $("#NumeroPoliza").val(); | |
var FechaTermino = $("#NumeroPoliza").val(); | |
var Estado = $("#Estado").val(); | |
var Sucursal = $("#Sucursal").val(); | |
var RutPropietario = $("#RutPropietario").val(); | |
var RutDvCorredor = $("#RutDvCorredor").val(); | |
var RutCorredor = $("#RutCorredor").val(); | |
var RutDvPropietario = $("#RutDvPropietario").val(); | |
var jsonObject = { | |
NumeroCotizacion: NumeroCotizacion, | |
NumeroPoliza: NumeroPoliza, | |
FechaInicio: FechaInicio, | |
FechaTermino: FechaTermino, | |
Estado: Estado, | |
Sucursal: Sucursal, | |
RutPropietario: RutPropietario, | |
RutDvCorredor: RutDvCorredor, | |
RutCorredor: RutCorredor, | |
RutDvPropietario: RutDvPropietario, | |
}; | |
$.ajax({ | |
type: "POST", | |
url: "/BitacoraCotizacionHogar/LlamarJson", | |
data: JSON.stringify(jsonObject), | |
contentType: "application/json; charset=utf-8", | |
dataType: "json", | |
success: function (data, textStatus, jqXHR) { | |
// since we are using jQuery, you don't need to parse response | |
console.log(data) | |
drawTable(data); | |
}, | |
error: function (data) { console.log(data) } | |
}); | |
function drawTable(data) { | |
for (var i = 0; i < data.length; i++) { | |
drawRow(data[i]); | |
} | |
} | |
function drawRow(rowData) { | |
var row = $("<tr />") | |
$("#personDataTable").append(row); //this will append tr element to table... keep its reference for a while since we will add cels into it | |
row.append($("<td>" + rowData.EstadoCotizacion.Nombre + "</td>")); | |
row.append($("<td>" + rowData.CotizacionId + "</td>")); | |
row.append($("<td>" + rowData.NumeroPoliza + "</td>")); | |
row.append($("<td>" + rowData.NumeroCotizacion + "</td>")); | |
row.append($("<td>" + rowData.FechaCotizacion + "</td>")); | |
row.append($("<td>" + rowData.FechaEmision + "</td>")); | |
row.append($("<td>" + rowData.RutAseguradoFormato + "</td>")); | |
row.append($("<td>" + rowData.NombreAsegurado + "</td>")); | |
row.append($("<td>" + rowData.DireccionPrincipal + "</td>")); | |
row.append($("<td>" + rowData.ComunaPrincipal + "</td>")); | |
row.append($("<td>" + rowData.NombreProducto + "</td>")); | |
row.append($("<td>" + rowData.Cobertura + "</td>")); | |
row.append($("<td>" + rowData.MontoAsegurado + "</td>")); | |
row.append($("<td>" + rowData.Comision + "</td>")); | |
row.append($("<td>" + rowData.PrimaNetaTotal + "</td>")); | |
row.append($("<td>" + rowData.SucursalPoliza + "</td>")); | |
} | |
}); | |
}); | |
</script> | |
<table id="personDataTable"> | |
<tr> | |
<th>Editar/Emitir</th> | |
<th>ID Cotizacion</th> | |
<th>N° Póliza</th> | |
<th>N° Cotizacion</th> | |
<th>Fecha Cotización</th> | |
<th>Fecha Emisión</th> | |
<th>Rut Asegurado</th> | |
<th>Nombre Asegurado</th> | |
<th>Dirección Inmueble</th> | |
<th>Comuna Inmueble</th> | |
<th>Nombre Producto</th> | |
<th>Cobertura</th> | |
<th>Monto Asegurado</th> | |
<th>Comision</th> | |
<th>Prima Neta</th> | |
<th>Sucursal</th> | |
</tr> | |
</table> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment