角度6传递对象具有IFormFile到API .netcore 2.1

时间:2019-03-01 08:42:15

标签: angular asp.net-core-2.1 iformfile

如何使用Angular 6将对象具有IFormFile属性传递给.netcore 2.1 API

我的模特:

 public class CreateUpdateWorkFlowObject
{

    public List<PhoiHopXuLyKNObject> PhoiHop { get; set;}
    public List<KhDinhKemChuyenTiep> DinhKem { get; set; }
    public List<IFormFile> Files { get; set; }
    public string SoCongVan { get; set; }
    public string NguoiKy { get; set; }
    public string CoQuan { get; set; }
    public string TrichYeu { get; set; }


}

像这样通过角度6传递数据的功能

createst(lstWorkflow: any, KNid: number, Startstep: number) {
var unitId = this.localStorage.getUnitId();
var accountId = this.localStorage.getAccountId();
if (lstWorkflow.length > 0) {
   const uploadData = new FormData();
  for (var i = 0; i < lstWorkflow.length; i++) {
    for (var j = 0; j < lstWorkflow[i].files.length; j++) {
      uploadData.append('myFile' + i, lstWorkflow[i].files[j], lstWorkflow[i].files[j].name);
    }
  }
  uploadData.append('lstWorkFlow', JSON.stringify(lstWorkflow));
  return this.http.post(AppSettings.API_ADDRESS + Api.WorkflowTest, uploadData);
}

}

然后通过控制器获取此数据

[HttpPost, DisableRequestSizeLimit]
    [Route("createWorkFlowTesst")]
    public UpdateWorkflowResponse createWorkflowTest()
    {
        var settings = new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Ignore,
            MissingMemberHandling = MissingMemberHandling.Ignore,
            DateFormatHandling = DateFormatHandling.IsoDateFormat,
            DateTimeZoneHandling = DateTimeZoneHandling.Unspecified,
            Culture = CultureInfo.GetCultureInfo("vi-VN")
        };
        var lstWorkFlow = JsonConvert.DeserializeObject<List<CreateUpdateWorkFlowObject>>(Request.Form["lstWorkFlow"], settings);

         }

当我运行代码时,出现如下错误: enter image description here

任何人都可以帮助我解决这个问题吗?

0 个答案:

没有答案