Bind multiple files to array with properties

Nickon

I have a basic HTML form with <input type="file" multiple> inside. For each chosen file I create a description.

Now I want to bind them to PostedPhotoViewModel[] PostedPhotos;:

public abstract class PostedPhotoViewModel
{
    public string Description { get; set; }
    public HttpPostedFileBase File { get; set; }
}

I don't know how to prepare my input to do such a thing. Is it possible? Or do I have to do some tricks to achieve my target?

@Html.TextBoxFor(m => m.PostedPhotos, new { @name = "PostedPhotos", type = "file", multiple="multiple" })

I tried to force it in such a way, but didn't work:

myForm.submit(function(e) {
    myInput.files = $.map(myInput.files, function(element) {
        return {File: element, Description: "Test description"}
    });
    return true;
});

It's basic ASP.NET MVC 5 project.

beautifulcoder

I would replace this:

@Html.TextBoxFor(m => m.PostedPhotos, new { @name = "PostedPhotos", type = "file", multiple="multiple" })

With just:

<input type="file" name="files" multiple="multiple" />

Then in the controller do something like:

[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)

I think the nested view model list binding with a textbox property is making it far more complicated than it is.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JavaFX bind to multiple properties

From Dev

Bind to multiple Properties in UWP

From Dev

JavaFX Bind Label textProperty to multiple Properties changes

From Dev

Loading multiple properties files with Camel

From Dev

How to bind a string array of properties in Spring?

From Dev

Sort an array of objects by multiple properties

From Dev

Validating multiple files in array

From Dev

Validating multiple files in array

From Dev

How to bind jbossws properties files to soap request and response message in soapui?

From Dev

Java: Load multiple properties files as one

From Dev

Loading multiple external properties files from spring

From Dev

Java: Load multiple properties files as one

From Dev

How to display multiple files properties using jQuery?

From Dev

Multiple files uploading in multidimensional array

From Dev

Multiple CSV files to PHP Array -

From Dev

Split a json array to multiple files

From Dev

How configure multiple gradle.properties files in Gradle for multiple projects?

From Dev

IndexOf Method for Multiple Properties in Object Array

From Dev

Working with multiple properties of array VB .net

From Dev

Automapper convert multiple properties into array/list

From Dev

how to filter array with multiple properties in angular

From Dev

Python read in multiple .txt files and row bind using pandas

From Dev

How to bind multiple JSON files in ng-repeat (AngularJS)?

From Dev

Python read in multiple .txt files and row bind using pandas

From Dev

Issue with loading multiple properties files with Spring <util:properties /> when the list of files is a parameter

From Dev

underscore js mapping array of objects multiple properties to new array

From Dev

Bind multiple values from the query string to an array parameter

From Dev

How to add multiple .properties files as build artifacts with Maven?

From Dev

Can Spring support multiple messages.properties files in classpath?

Related Related

  1. 1

    JavaFX bind to multiple properties

  2. 2

    Bind to multiple Properties in UWP

  3. 3

    JavaFX Bind Label textProperty to multiple Properties changes

  4. 4

    Loading multiple properties files with Camel

  5. 5

    How to bind a string array of properties in Spring?

  6. 6

    Sort an array of objects by multiple properties

  7. 7

    Validating multiple files in array

  8. 8

    Validating multiple files in array

  9. 9

    How to bind jbossws properties files to soap request and response message in soapui?

  10. 10

    Java: Load multiple properties files as one

  11. 11

    Loading multiple external properties files from spring

  12. 12

    Java: Load multiple properties files as one

  13. 13

    How to display multiple files properties using jQuery?

  14. 14

    Multiple files uploading in multidimensional array

  15. 15

    Multiple CSV files to PHP Array -

  16. 16

    Split a json array to multiple files

  17. 17

    How configure multiple gradle.properties files in Gradle for multiple projects?

  18. 18

    IndexOf Method for Multiple Properties in Object Array

  19. 19

    Working with multiple properties of array VB .net

  20. 20

    Automapper convert multiple properties into array/list

  21. 21

    how to filter array with multiple properties in angular

  22. 22

    Python read in multiple .txt files and row bind using pandas

  23. 23

    How to bind multiple JSON files in ng-repeat (AngularJS)?

  24. 24

    Python read in multiple .txt files and row bind using pandas

  25. 25

    Issue with loading multiple properties files with Spring <util:properties /> when the list of files is a parameter

  26. 26

    underscore js mapping array of objects multiple properties to new array

  27. 27

    Bind multiple values from the query string to an array parameter

  28. 28

    How to add multiple .properties files as build artifacts with Maven?

  29. 29

    Can Spring support multiple messages.properties files in classpath?

HotTag

Archive