0

I am trying to pass a list of objects to Controller using ajax, it works and shows how many items are there but shows items as null and I do not know what I am misisng.

I have this in JavaScript:

        var data = {
        "expediente": '@Model.NUMEMP',
        "edad": '@edad',
        "sexo": '@Model.SEXO',
        "piezasConNotas": piezasYNotas,
        //"servicio": $("#actividades").val(),
        //"subServicio": $("#actividadesRealizar").val(),
        "diagnostico": $("#diagnosticos").val(),
        "interconsulta_esp": "",
        "interconsulta": $("#interconsulta").val(),
    };

    console.log(data);

     $.ajax({
         'url': ' @Url.Action("AgregarExpedienteDental", "ServiciosMedicos")',
        "data": data ,
        "success": function (result) {
            if (result === "1") {
                //swal("Good job!", "You clicked the button!", "success");
                Swal.fire('Success', 'Se ha insertado', 'success');
                setTimeout('', 3000);

                const myTimeout = setTimeout(myGreeting, 1500);
            }
        },
        "error": function (response) {
        }
     });

this is what console.log(data) shows:

enter image description here

and when I send them to controller this is how it shows in the debugger:

enter image description here

as you can see other data is ok and the count from the list is ok but the items are going inside as null. I do not know what I am doing wrong? How do I solve this?

this is my C# code:

 public JsonResult AgregarExpedienteDental(ExpedienteDentall data)
 {
        ....
 }

 public class ExpedienteDentall
    { 
        public string diagnostico { get; set; }
        public string edad { get; set; }
        public string expediente { get; set; }
        public string interconsulta { get; set; }
        public string interconsulta_esp { get; set; }
        //public string servicio { get; set; } = "";
        public string sexo { get; set; }
        //public string subServicio { get; set; } = "";
        public List<piezasConNotas> piezasConNotas { get; set; }
    }

    public class piezasConNotas
    {
        public string diente { get; set; }
        public string nota { get; set; }
        public string actividad { get; set; }
        public string actividadRealizada { get; set; }

    }
Reyneer Leon
  • 356
  • 2
  • 14

0 Answers0