Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
3.22/5 (2 votes)
See more:
I want to get all files that are selected in input file to c# object, but it select only one files from mutiselected files to display in text box.

What I have tried:

Input file to select multiple files:
<input type="file" name="File2" id="File2" accept="image/*" multiple/>

Input text to display all selected files:
@Html.EditorFor(model => model.DocumentName, new { htmlAttributes = new { @id = "documentName", @class = "form-control" } }) 


Model:
[Display(Name = "DocumentName", ResourceType = typeof(Resources.Resources))]
       public override string DocumentName
       {
           get { return base.DocumentName; }
           set { base.DocumentName = value; }
       }


What changes are required in my code, to resolve it?
Posted
Updated 8-Aug-17 0:56am

1 solution

You can Add this in your script. This should work when you try to select multiple files on upload, for example, in OnChange Functionality.

JavaScript
 $("document").ready(function(){
$("#File2").change(function() {
    var files = $(this)[0].files;
for (var i = 0; i < files.length; i++) {
    $("#documentName").val(files[i].name);
}    });});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900