I'm looking for best approach suggestions for the below scenario:
- A user can choose one or more csv files to validate(Attachment 1) which on "validate" button click goes through the validation code(showing progress bar till it returns an output).
- A return response is either a success message or the error details for each file chosen to validate(Attachment 2)
- A successfully validated file can now be uploaded to azure storage with an "Upload" button.
Now, to make everything asynchronous, my thought is that the view needs to have individual flexible section for each file.
I'm working with MVC5 razor views with knockout.js, I have decent idea about partial views but I am not certain on how to go about this. If not partial views, then what would be the best approach.
Going with a partial view will work. Just have one partial view with the basic table layout for what you need. Then have
in your main form that is hidden. Post your file using knockout or jquery to your upload action. Let the action return your partial view. Then using knockout or jquery's success callback, do something like this:
to insert your partial view's html
Kind of, what I think you need is a separate model/class for the files in order to run ajax commands on demand, at least that's how I understood your explanation.
Check out this jsfiddle, I have added some random true/false and string stuff to try and mimic your layout as quickly as possible. For testing try to use 5 or more files (random generators are kind of finicky in JS).
https://jsfiddle.net/n2ne6yLh/10/
So essentially you listen for a change event on the file input. Map each file to a new model "FileModel" in this case, then push it into the observableArray Files. Each FileModel houses it's own individual results, validation functions etc. Then the layout takes care of the rest.
You will have need to look into the FormData Web API in order to do stuff with the files in Javascript. If your clients/users are using outdated browsers there a shims/polyfills for the FormData stuff, jquery and what have you. https://developer.mozilla.org/en-US/docs/Web/API/FormData
What about the following simple algorithm
Let's assume in your html you have a < div id="allFiles">
You can write the following in your main view file
This way most of you code is on the ServerSide,all you need is some jquery code to replace parts of the page once a validation of a file has been completed