简体   繁体   English

模型绑定不适用于嵌套对象

[英]Model binding not working for nested object

I am trying to bind data in my model posted from postman in my below model: 我试图在我的模型中绑定从邮递员发布的模型中的数据:

public class VariantModel
{
    public int Id { get; set; }     
    public List<SubvariantModel> Subvariants { get; set; }
}

public class SubvariantModel
{
    public int Id { get; set; }
    public string Description { get; set; }
    public IFormFile Document { get; set; }
}

Every property is getting populated but only Document property is coming null as you can see here : 每个属性都会被填充,但只有Document属性为null,如下所示:

在此输入图像描述

But surprisingly when i inspect http request object i see that file : 但令人惊讶的是,当我检查http请求对象时,我看到该文件:

在此输入图像描述

This is how i am posting data from POSTMAN : 这是我从POSTMAN发布数据的方式: 在此输入图像描述

在此输入图像描述

Code : 代码:

[HttpPost]
public void Post([FromForm]VariantModel emp)
{
    var d = HttpContext.Request;
}

Can anybody tell me what could be the issue here? 谁能告诉我这里可能出现什么问题?

Update : 更新:

在此输入图像描述

This is an issue I encountered as well. 这也是我遇到的问题。 It is a known issue with nesting IFormFile as a View Model property in .NET Core v2.2. 将IFormFile嵌套为.NET Core v2.2中的View Model属性是一个已知问题。

The fix that worked for me is here . 对我有用的修复就在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM