From a table where the user can add, delete and modify their values, you get a data type like the one shown below (which I can not change its format or data type) [here the code of the table ]:
var info = [{
nombres: 'Juan',
apellidos: 'Pérez',
email: '[email protected]',
pass: '123juan'
}, {
nombres: 'Julio',
apellidos: 'López',
email: '[email protected]',
pass: 'passjulio'
}];
But on the server side, it is obtained from Request.Params, when debugging and seeing the values obtained from the post, instead of arriving at the previous list as an array or object, each value arrives separately, which makes complex your iteration to then save them in the BD:
This is the driver code:
public JsonResult MiAction()
{ var x = Request.Params["info[]"];
return Json("ok");
}
And this is the form and the script:
function enviar_usuarios() {
var info = [{
nombres: 'Juan',
apellidos: 'Pérez',
email: '[email protected]',
pass: '123juan'
}, {
nombres: 'Julio',
apellidos: 'López',
email: '[email protected]',
pass: 'passjulio'
}];
var info2=[];
info2[1] = info;
$.ajax({
data: { "info": info2 }, //datos que se envian a traves de ajax
url: '/Home/MiAction', //archivo que recibe la peticion
type: 'post', //método de envio
success: function (response) {
console.log(response);
}
});
}
<input type="button" onclick="enviar_usuarios()" id="btn" value="Ir">
And this last are some attempts of solution that have not worked from the following variable
var info = [{
nombres: 'Juan',
apellidos: 'Pérez',
email: '[email protected]',
pass: '123juan'
}, {
nombres: 'Julio',
apellidos: 'López',
email: '[email protected]',
pass: 'passjulio'
}];
var formData = new FormData();
formData.append("lista", lista_JSON);
var formData = {"lista": lista_JSON, "lista2": [lista_JSON], "lista3": {lista_JSON}};
var formData = { lista: lista_JSON};