Good day everyone,
I'm trying to pass my ViewModel from JS to my ASP.NET Core Controller but I'm facing an error code with 500.
Here are my codes:
My Javascript
const myFiles = new FormData(); // I supply this myFiles from my append.
// supposed myFiles has already files inside so don't worry about this.
const myInfo = {
Id: 0
Name: "Hello World"
}
const vm = {
MyInfo: myInfo,
MyFiles: myFiles
}
axios.post(`/Info/UploadInfo`,
vm,
{
headers:{
"Content-Type": "multipart/form-data"
}
});
My ViewModel
public class MyInfoVm{
public MyInfo MyInfo {get;set;}
public IFormCollection MyFiles {get;set;}
}
My Controller
public IActionResult UploadInfo(MyInfoVm vm){
return Ok();
}
This is working if I remove the VM and solely use one of the fields (either IFormCollection or MyInfo ) in the ViewModel. But the problem is, I need to send multiple parameters in single request. Any help please?