【问题标题】:415 Undocumented Error: Unsupported Media Type in asp.net core web api using multipart/formdata in [frombody]415 Undocumented Error: Unsupported Media Type in asp.net core web api using multipart/formdata in [frombody]
【发布时间】:2020-11-24 13:27:16
【问题描述】:

我有类模型,我需要使用带有[frombody] 的多部分表单数据将其传递给我的控制器,但我的 api 给了我

错误 415 asp.netcore 中不支持的媒体类型

   public class MedcoExpertModel
    {
        [JsonProperty(PropertyName = "ID")]
        public int ID { get; set; }
        [JsonProperty(PropertyName = "NamePrefix")]
        public string NamePrefix { get; set; }
        public IFormFile Signaturefile { get; set; }
        public IFormFile CVfile { get; set; }
        public IFormFile AccCertificatefile { get; set; }
        public IFormFile Contractfile { get; set; }
        public IFormFile ICOfile { get; set; }
        public IFormFile Insurancefile { get; set; }
        public IFormFile MedcoCertificatefile { get; set; }


    }

控制器是

        [HttpPost]
        [Consumes("multipart/form-data")]
        [EnableCors("AllowOrigin")]
        public async Task<ActionResult<OutputWarapper<OutputData>>> AddMedcoExpert([FromBody] MedcoExpertModel medcomodel )
        {
            try
            {
                var sample = await _iexpert.AddMedcoExpert(medcomodel);
                
                return Ok(sample);

            }
            catch (Exception)
            {
                return StatusCode((int)HttpStatusCode.InternalServerError);
            }
        }

如果我使用 fromform 而不是 frombody.api 方法命中方法。但我需要使用 frombody 和 multipart/formdata 传递值。

【问题讨论】:

    标签: asp.net-core


    【解决方案1】:

    我明白了。如果我们使用 Multipart/farmdata,那么我们可以使用 fromform 代替 formbody。我们可以在类模型中传递所有内容。

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 2019-05-19
      • 2020-11-14
      • 2017-11-16
      • 2022-10-13
      • 2020-09-20
      相关资源
      最近更新 更多