formsasp.net-corefile-upload.net-6.0model-binding

Hi, can I upload multiple images using single input tag in net core 6 and also bind with model?


I'm trying to build and form in which you can upload gallery items.

here is the Html tag.

<input type="file" multiple="true"/>

but above is not working for me and also, I want to get the list of files in controller so what type will be used and how to bind with single input tag.


Solution

  • Here is a demo to pass multiple files with form:

    form:

    <form method="post" encytype="multipart/form-data" asp-action="GetFiles">
        <input name="files" type="file" multiple />
        <input type="submit" value="submit" />
    </form>
    

    action:

    public void GetFiles(List<IFormFile> files)
    {}