简体   繁体   中英

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 :

在此输入图像描述

But surprisingly when i inspect http request object i see that file :

在此输入图像描述

This is how i am posting data from 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.

The fix that worked for me is here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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