Saurav
Saurav

Reputation: 1

JQuery ajax FormData: files not added to POST

I want to upload files using Jquery Ajax with Form Data.Like this

Jquery:

   function UploadFile(i) {

    var data = new FormData();

    var files = [];
    if ($('#PrintingSide').val() == "1") {
        files.push($("#FrontFile" + i).get(0).files);
    }
    else {
        files.push($("#FrontFile" + i).get(0).files);
        files.push($("#BackFile" + i).get(0).files);
    }
   

    for (var i = 0; i < files.length; i++) {
        data.append(files[i].name, files[i]);
       
    }
    
        $.ajax({
        type: "post",
        url: "@Url.Content("~/UserEstimation/UploadMultipleFiles")",
        processData: false,
        contentType: false,
        data: data,
        success: function (data) {
          }
    });
    
}

but in my action method i am getting 0 files.where i am doing the mistake? I have 2 independent input file types,like this : enter image description here

Controller:

 public ActionResult UploadMultipleFiles()
    { 
        for (int i = 0; i < Request.Files.Count; i++)
        {
          // do something here 
        }
    }

Upvotes: 0

Views: 59

Answers (1)

Saurav
Saurav

Reputation: 1

After 6 hour of Search and findings,I got solution of this weird issue.. the problem was file size, i just made some changes in web.config and Hurrehh..

 <httpRuntime targetFramework="4.5"  maxRequestLength="2097151" />

Upvotes: 0

Related Questions