Javascript 带有IFormCollection的ViewModel不';无法处理错误500-ASP.NET内核

Javascript 带有IFormCollection的ViewModel不';无法处理错误500-ASP.NET内核,javascript,c#,asp.net-mvc,viewmodel,asp.net-core-2.0,Javascript,C#,Asp.net Mvc,Viewmodel,Asp.net Core 2.0,大家好, 我试图将我的ViewModel从JS传递到我的ASP.NET核心控制器,但我遇到了一个错误代码500 这是我的密码: 我的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

大家好,

我试图将我的ViewModel从JS传递到我的ASP.NET核心控制器,但我遇到了一个错误代码500

这是我的密码:

我的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"
        }
    });
var fileForm = document.createElement('form');
fileForm.enctype = 'multipart/form-data';
var id = document.createElement('input');
id.name = 'id';
id.value = '0';
fileForm.appendChild(id);

var name = document.createElement('input');
name.name = 'id';
name.value = '0';
fileForm.appendChild(name);

var fileInput = document.createElement('input');

fileForm.appendChild(fileInput);
fileInput.id = 'file-input';
fileInput.type = 'file';
fileInput.name = 'file';

var data = new FormData(fileForm);
我的视图模型

public class MyInfoVm{
    public MyInfo MyInfo {get;set;}
    public IFormCollection MyFiles {get;set;}
}
我的控制器

public IActionResult UploadInfo(MyInfoVm vm){
    return Ok();
}
如果我删除虚拟机并仅使用ViewModel中的一个字段(IFormCollection或MyInfo),则这是可行的。但问题是,我需要在一个请求中发送多个参数。有什么帮助吗?

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"
        }
    });
var fileForm = document.createElement('form');
fileForm.enctype = 'multipart/form-data';
var id = document.createElement('input');
id.name = 'id';
id.value = '0';
fileForm.appendChild(id);

var name = document.createElement('input');
name.name = 'id';
name.value = '0';
fileForm.appendChild(name);

var fileInput = document.createElement('input');

fileForm.appendChild(fileInput);
fileInput.id = 'file-input';
fileInput.type = 'file';
fileInput.name = 'file';

var data = new FormData(fileForm);

IFormCollection
可以同时收集字段和文件,Javascript
表单可以同时发送这两个字段和文件。我会把你的
info
作为字段放在表单中。你不能混合对象和
FormData
-你需要将你的其他名称/对值(
Id:0
name:“Hello World”
)附加到
FormData
-参考@Tim那里有简单的代码示例吗?我会找到一个。你说@Tim是什么意思