html - save input type file state after server validation mvc -


i have html form textbox controls , <input type=file> control uploading file. controls have server validation. imagine next situation: select file uploading , enter data textbox controls(some textboxes leave blank). click submit button , form sended server action. after validation checking in server redirect same form error correction. textboxes save state , have data file control don't have.

p.s. when debugging code, see uploaded file in view model. can resend html form? don't write code because think redundant.

you can filename (eg. myfile.txt), not full path (eg. /home/martin/myfile.txt or c:/users/martin/myfile.txt), can't set value server-side or javascript. reasons of security & privacy.

what can instead:

  1. validate form javascript or ajax request, if fails, original form (& values) unchanged (i recommend this).

  2. save file contents on first try, , if retry fails , user didn't give new file, use saved file contents (this may require special coding, , may leave orphaned files/db rows if user didn't go second try & gave instead. wouldn't recommend this).


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -