I'm trying to do something I would think is fairly simple, but I must be missing the syntax.
function removeFile(filename) {
var json = { "fileName": filename };
$.ajax({
type: 'post',
url: "home/RemoveFile",
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function(result) {
alert("good:" + result);
},
failure: function (response) {
alert("bad:" + response.d);
}
});
}
And to receive the filename in the controller:
[HttpPost]
public JsonResult RemoveFile(string fileName)
{
if (fileName == null) return Json(" {'result' : 'failure'}");
FileUpload fileUpload = new FileUpload(_hostingEnvironment, _settings);
Boolean removeFile = fileUpload.RemoveFile(fileName);
return Json(" {'result' : 'ok'}");
}
the fileName is always null, yet Fiddler shows the Json being passed as:
- JSON
-fileName=2851cd1d-f364-4f00-8824-0792cf6ca598\Capture-after.JPG
What am I doing wrong?