I Love Stackoverflow
I Love Stackoverflow

Reputation: 6868

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 :

enter image description here

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

enter image description here

This is how i am posting data from POSTMAN : enter image description here

enter image description here

Code :

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

Can anybody tell me what could be the issue here?

Update :

enter image description here

Upvotes: 7

Views: 2987

Answers (1)

Graham Meehan
Graham Meehan

Reputation: 465

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.

Upvotes: 1

Related Questions