I'm using the ASP.NET Web API. I have an action in my controller which works fine if there's no parameter. If there is a parameter, like:
public string UploadFile(string actionType)
then my action isn't called and I get the following message, viewed in Fiddler:
No 'MediaTypeFormatter' is available to read an object of type 'String' with the media type 'multipart/form-data'
The route in my global.asx
is as follows:
"api/{controller}/{action}/{actionType}"
I'm using Jquery Post to call the action:
function upload() {
var actiontype = $("input:radio[name=actiontype]").val();
var formData = new FormData($('form')[0]);
$.ajax({
url: 'api/uploads/uploadfile/' + actiontype,
type: 'POST',
success: function (data) {
$("#mydiv").append(data);
},
error: function (data) {
$("#mydiv").append(data);
},
data: formData,
cache: false,
contentType: false,
processData: false
});
};
Here's my action method:
public string UploadFile(string actionType)
{
if (Request.Content.IsMimeMultipartContent())
{
//Save file
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/Files"));
Request.Content.ReadAsMultipartAsync(provider);
}
return string.Format("Action {0} Complete!", actionType);
}
Is this a known problem, with a workaround? How can I have a simple action with parameter?