2
Answers

How to pass IFormFile data from js code to c# action method

Gaurav Babbar

Gaurav Babbar

8y
754
1

var onFileUploadChange = function () {        

var originalEvent = document.getElementById("fileUpload");        

var files = originalEvent.files;

        if (typeof FormData == "undefined") {            

var data = [];         }        

else {           

var data = new FormData();       

}

        for (var i = 0; i < files.length ; i++) {            

data.append(files[i].name, files[i]);  break;       

}     

$.ajax({            

type: "POST",            

url: _url,            

dataType: "html",            

contentType: false,            

processData: false,            

data: data,            

success: function () {             },           

error: function (xhr) {                

console.log(xhr);            

}        

});   

}


I will get the values in "Request" object at c# action method, Is there any way that I will get this value in action method parameter model instead.????

Thanks


 

Answers (2)