I am sending a file input in FormData to a web api as below. The api method expects one additional parameter as well but the below code works only without the parameter in api. How can I send the additional parameter to the api. Thanks for any suggestions!
<div>
<label for="add">Add Customer</label>
<input type="file" onchange="AddCust(event)" />
</div>
function AddCust(event)
{
Add("testtype", event.target.files[0]);
}
function Add(type, file)
{
var imageData = new FormData();
imageData.append("myfile", file);
$.ajax({
url: _uri + '/party/Add',
type: 'POST',
enctype: 'multipart/form-data',
data: imageData,
cache: false,
contentType: false,
processData: false,
crossDomain: true,
xhrFields: { withCredentials: true },
success: function (data) {
$("#log").append("Add - Success " + data.toString() + "</br>");
},
error: function (xhr, ajaxOptions, thrownError) {
$("#log").append("Add - Error " + xhr.responseText + "</br>");
}
});
Web API:
[HttpPost]
public async void Add(string customertype)
{
var provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/App_Data"));
await Request.Content.ReadAsMultipartAsync(provider);
}