I've got a simple form in an MVC app I've made. It contains a file field so users can upload an image. It all works great.
Problem is, if the form submit fails validation the content of the file field is lost (other fields remain populated, thx HtmlHelpers!). How do I keep the file field populated after a failed validation?
TIA!
Browsers are designed in such way because of security risks. It's impossible to set value of file input box in HTML source or by Javascript. Otherwise malicious script could steal some private file without user attention.
There is an interesting information about the subject.
As far as I know you cannot set the value of a HTML file input box. I would suggest coupling the file input box with a label or text box.
Then you can populate the it with the value from the file input box to be resubmitted later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With