Reputation: 11
I want to get all files that are selected in input file to c# object, but it select only one file from mutiselected files to display in text box.
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?
Upvotes: 0
Views: 169
Reputation: 326
Please Add this in your script. It will works when selecting files on upload i.e OnChange Functionality. Please Try it and Let me know.
$("document").ready(function(){
$("#File2").change(function() {
var files = $(this)[0].files;
for (var i = 0; i < files.length; i++) {
$("#documentName").val(files[i].name);
} });});
Upvotes: 0