Skip to content

IFormFile bind error when using in sub collection #4802

Closed
@megafetis

Description

@megafetis

Describe the bug

When i trying to post form with sublist of images models with IFormFile properties, the program starts to hang!
see the screen

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core '2.2'
  2. Run this code
public class CategoryCreateModel
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public int Priority { get; set; }
        public string Abbr { get; set; }
        public string Description { get; set; }
        public string LinkName { get; set; }
        public string ParentId { get; set; }
// here error binding
        public IList<AppImageEditModel> Images { get; set; }
    }

//uploaded images sub collection
public class AppImageEditModel
    {
        public string Id { get; set; }
        public int Priority { get; set; }
        public string Name { get; set; }
        public string ImageUrl { get; set; }
// if class contains IFormFile prop, hapends binding bug
        public IFormFile AppImageFile { get; set; }
        public AppImageType ImageType { get; set; }
        public bool IsMain { get; set; }
    }

// in controller action:
        [HttpPost]
        public async Task<IActionResult> Create(CategoryCreateModel model)
        {
            if (ModelState.IsValid)
            {
                await Mediator.Send(model);
                return RedirectToAction("Index");
            }
            return View(model);
        }

No errors thrown, but frease executing:
operative memory encreases from 100 megabytes to 3-4 gigabytes!!!

Screenshots when I submit form:

Increase memory screen
Increase memory screen

Expected behavior

The execution is not come to action method and hangs

Binding in razor inside the form:

<form asp-action="Create" enctype="multipart/form-data">
...
<input type="text" name="Images[0].Name" id="Images_0__Text" />
<input type="file" name="Images[0].AppImageFile" id="Images_0__AppImageFile" />

<input type="text" name="Images[1].Name" id="Images_1__Text" />
<input type="file" name="Images[1].AppImageFile" id="Images_1__AppImageFile"/>

Additional context

if you delete the property public IFormFile AppImageFile from class AppImageEditModel, the program will work well!

Metadata

Metadata

Assignees

Labels

✔️ Resolution: Won't FixResolved because we decided not to change the behavior reported in this issue.area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesblockedThe work on this issue is blocked due to some dependencybugThis issue describes a behavior which is not expected - a bug.feature-model-binding

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions