Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

74
Vistas
Javascript ajax post a complex object with an array of complex objects inside

As title, I have a problem with this that I saw my array of the object is empty at the back end. For example, I've defined 2 classes at the back end...

    public class ScoreModel { 
        public string Subject { get; set; }
        public float Score { get; set; }
    }
    public class StudentTestModel
    {
        public string Name { get; set; }
        public ScoreModel[] Scores { get; set; }
    }

At the code shown upper, the classStudentTestModel has an array of ScoreModel that contains 2 simple data members. Then at the front end, I use jQuery library to call back end like this....

$("#btnCountScore").click(function () {
                var frm = new FormData();
                frm.append("Name", "Garfield");
                var r = [
                    { "Subject": "Chinese", "Score": 89 },
                    { "Subject": "English", "Score": 87 },
                    { "Subject": "Math", "Score": 76 },
                    { "Subject": "NaturalScience", "Score": 90 },
                    { "Subject": "SocialScience", "Score": 83 },
                ];
                var r_form = [];
                for (var i = 0; i < r.length; i += 1) {
                    var f = new FormData();
                    f.append("Subject", r[i].Subject);
                    f.append("Score", r[i].Score);
                    r_form.push(f);
                }
                frm.append("Scores", r_form);
                $.ajax({
                    url: "../Home/CountScore",
                    method: "post",
                    processData: false,
                    contentType: false,
                    data: frm,
                    success: function (ret) {
                        $("#lblShowAverage").text(ret);
                    }
                });
            });

When I debug, I can see the Name contains value but Scoures is an empty array at my back end, then I couldn't get what I want. Could someone guide me a way to correct this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Have you tried to make the object into json before sending it then deserialize it in the backend?

FrontEnd: JSON.stringify(frm)

Backend: JsonSerializer.Deserialize(jsonString);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda