I am trying to post the values to the controller via ajax post. Here my problem is I am using Serialize method to post the form values. I have to send Images as well. How can I send images and form data and what should be the controller method that accepts both files and model values?
I am getting all the text values like this
var files = $("#formid").serialize();
I am getting images like this
var form1Data = new FormData();
var totalFiles = document.getElementById("files").files.length;
for (var i = 0; i < totalFiles; i++) {
var file = document.getElementById("files").files[i];
form1Data.append("files", file);
}
In ajax call I have to send both files and formdata. How to send in the ajax call
$.ajax(
{
url: "/Home/PostanAd/",
type: "POST",
data: { form1Data: form1Data, files: files },
contentType: false,
processData: false,
});
can some one please suggest the answer?