1

Please note that the reason of this question being asked is that I have gone through similar questions but none seemed to solve my problem.

remove specific file form multiple file input

Remove a FileList item from a multiple "input:file"

How to delete a specific file from input type file multiple?

How do I remove a file from the FileList

etc.

Also, please be aware I do not want to use a third party as advised here:

gmail style file upload in c#

Goal

I want to upload files to a .NET Core form and show their names immediately with a text beside them saying "Remove", so I have the opportunity to remove them before submitting the form.

Problem

Even though the solutions above seemed to working running in JSFiddle, putting the input type="file" tag into a .NET Core form seems to ruin their functionality. I understand that FileList cannot be changed and hence these solutions using workarounds to save the uploaded files into an array and editing those, but for some reason this does not work in a Razor view form, I either delete all files from the input, or none of them.

Failures

I would like to get some help how to solve this problem, as I'm not too sure what would be the best approach. I understand that I can have multiple forms on one page, such as

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new {})) {
    // to call HomeController's Upload method and upload the files
}

@using (Html.BeginForm("Submit", "Home", FormMethod.Post, new {})) {
    // to call HomeController's Submit method and get all data from the form
}

but I don't know how could I associate the files from Upload method to the other form's data (Name, Address, etc), as these are 2 different forms.

So there are 2 key points:

1. Show the uploaded files to the user and let them remove it on demand one-by-one before submitting the form

2. Bind these uploaded files to the form

Please tell me if I'm overcomplating this and there's an easier solution to upload multiple files to a form and let them to be removed one-by-one before the user hits the "Send" button.

Thank you for your ideas.

faravo
  • 11
  • 2
  • 1
    We need more information about what you've tried (i.e. your actual code). None of this has anything to do with .NET Core, ASP.NET Core, or Razor, as those are all server-side technologies and this is running client-side in JS. Likely, it's something silly like the id of the form field not being correct or what you assume it to be. However, again, we'd need your code to tell if that's the case. – Chris Pratt Dec 06 '19 at 13:56

0 Answers0