I am trying to do an ASP.NET file upload via ajax. I have this ajax call in place:
$.ajax({
type: "POST",
url: '/Home/Upload',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert('success!!');
$("#" + id).attr('disabled', false);
},
error: function (error) {
alert("errror");
}
});
and this is my .NET code:
[HttpPost]
public void Upload()
{
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
string path = Path.Combine(Server.MapPath("~/UploadedFiles"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
}
}
When I goto the folder, I can see its been uploaded, but for some reason the ajax returns the alert error, please help.