views:

57

answers:

2

I have an ASP.NET MVC page with multiple file uploads. After a failed post, all the file upload boxes are blanked out. I don't want the user to need to reselect all the uploaded files. Is there a way I can preserve the values in these fields if other fields fail to validate on Post?

I could do the uploads via AJAX, but this would be more complex as I'd need to ensure they were cleaned up if the user decided not to submit the form in the end.

+1  A: 

You need to write your upload view so that you can pass default values to the text boxes.

When your user submits the file upload from your upload view, you will have all of the values for the text boxes in your controller method. Then, when your post fails, you can simply pass the values back to your upload view to populate the text boxes, rinse and repeat.

Robert Harvey
As far as I know there's no way to "pass default values" to the file selection box - for security reasons.
queen3
See http://www.cs.tut.fi/~jkorpela/forms/file.html#value
queen3
A: 

Actually, FireFox does preserve value. But you can't preserve it (set on server) according to http://www.cs.tut.fi/~jkorpela/forms/file.html#value. So I think your best way is AJAX. If you can actually clear the value.

Also, not sure if this will help, but try http://jquery.malsup.com/form/ which does file upload in iframe.

Or let user choose a better browser ;-)

queen3
Yes - looks like File Upload boxes can't generally have their values set. Thanks for the help.
Freewalker