【发布时间】: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