问题描述
我创建了一个新的 Asp.Net Core 5.0 Web API 项目,并尝试将文件与其他属性一起上传。其中一个属性是我定义的其他元素的列表。数据模型如下所示:
public class Person
{
public string Surname { get; set; }
public string FamilyName { get; set; }
public IFormFile Image { get; set; }
public List<Item> Items { get; set; } = new List<Item>();
}
public class Item
{
public string Value { get; set; }
public string Description { get; set; }
}
似乎 swagger 文档生成了具有适当 UI 的适当文件。不幸的是,我不知道数据必须是哪种格式,以便 ASP.NET Core 模型绑定器将其转换为有效模型。我试图将一些 json 对象插入到“项目”框中,但我的列表始终为空。
控制器动作非常标准:
[HttpPost]
public ActionResult Post([FromForm] Person p)
{
if (ModelState.IsValid)
{
return Ok();
}
return BadRequest();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)