Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

376
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!