Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

378
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda