I'm using jQuery ajax to upload file but want to add some parameters on webapi method, here is:
var data = new FormData();
data.append("file", $("#file")[0].files[0]);
data.append("myParameter", "test"); // with this param i get 404
$.ajax({
url: '/api/my/upload/',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function (data) {
console.log(data);
}
});
The Webapi controller:
public class MyController : ApiController
{
public string Upload(string myParameter)
{
return System.Web.HttpContext.Current.Request.Files.Count.ToString() + " / " + myParameter;
}
}
Without myParameter everything work but when I include myParameter on formdata and api method I get 404, any chance to make it work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…