I have a view that accept a file like so:
<form method="post" id="myform" enctype="multipart/form-data"
asp-controller="UploadFiles" asp-action="Index">
<div class="form-group">
<div class="col-md-10">
<p>Seleziona un file ORI ed un file MOD.</p>
<label for="fileOri">Seleziona ORI</label>
<input id="fileOri" type="file" name="fileOri" multiple />
<p></p>
<label for="fileMod">Seleziona MOD</label>
<input id="fileMod" type="file" name="fileMod" multiple />
<p></p>
<input id="check" name="checkBoxCorreggi" type="checkbox" />
<label for="check">Correggi Checksum</label>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<p></p>
<input type="button" id="VerificaChecksum" value="Verifica Checksum" onclick="fileUpload()" />
<!--value= "Verifica Checksum-->
<p></p>
</div>
</div>
</form>
and a Controller like so:
public class UploadFilesController : Controller
{
[HttpPost("UploadFiles")]
public virtual string UploadFiles(object obj)
{
return "Just a test";
}
}
What I'm trying to achieve is to passing a file from the client to the Controller, I've read a lot around but so far none has worked at all, this is my javascript code that it is supposed to call my controller:
function fileUpload() {
var fd = new FormData();
var xhr = new XMLHttpRequest();
var file = document.getElementById("fileOri").files[0];
fd.append("file", file);
xhr.open("POST", "/Home/Dll194/UploadFiles", true);
xhr.send()
}
But my breakpoints in VS2017 in the controller code are not being hits, am I doing something wrong? Can someone please clarify the process of sending a file to an MVC controller? I'm working with MVC and Netcore 2.1.
EDIT: By analyzing my call in Fiddler it says that the response from the call was OK (200), so I don't understand why my breakpoints on my controller are not hit. Thanks!