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

377
Vistas
how to append model object to formData in AJAX and retrieve using asp.net

I developed an Ajax POST method to pass the data to the controller. First I append my uploaded file to formData. Then I want to bind a model object to it. I did it. But in the controller, my model is always null.

Please help me how to append correctly and get the model and file correctly javascript function:

         var $file = document.getElementById('file'),
                $formData = new FormData();

            if ($file.files.length > 0) {
                for (var i = 0; i < $file.files.length; i++) {
                    $formData.append('file-' + i, $file.files[i]);
                }
            }       
            var SnapShotReceivedData = [{
               
                REASON: REASON_EXEMPT,
                COMMENT: COMMENT_EXEMPT,
                ATTACHMENT: $formData
            }];
            SnapShotReceivedData = JSON.stringify({ 'SnapShotReceivedData': SnapShotReceivedData})
            $formData.append('SnapShotReceivedData',SnapShotReceivedData);   

            $.ajax({
                contentType: false;
                processData: false,
                type: 'POST',
                url: '@Url.Action("SetHCMNIDSnapData", "Home")',
                data: $formData ,
                success: function (result) {                       
                   
                },
                failure: function (response) {
                    //  $('#result').html(response);
                }
            });

Controller:

       public JsonResult SetHCMNIDSnapData(List<SnapShot> SnapShotReceivedData)
        {                  
            if (Request.Files.Count > 0)
            {
                foreach (string file in Request.Files)
                {
                    var _file = Request.Files[file];
                }
            }
        }

my model is SnapShotReceivedData.When I debug the controller, the model object always null. please help me to solve this.

about 4 years ago · Juan Pablo Isaza
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