开发者

asp.net mvc C# file upload value persistance

i am using file upload on the user front. is there any way if some exception occurs the html file control is able to persist its value on post back(i know it can't) but any work around?. i am using server side vali开发者_如何学运维dations.


This could get messy.

Just a couple of points,

If an exception occurs do you really think it is wise to save the file?

By its nature an exception is telling you an error has occurred and processing should not continue. I would think the only time you should save the file is when you can recover or handle the exception without any side affects.

In which case you have to ask yourself, can you not just prevent the exception in the first place?

Always, always do validation on BOTH client and server side.

Why? Well to prevent this sort of thing, at least as much as possible. Let the user know there is a problem before posting, much better experience for them.

It terms of the problem, the best thing you could do is potentially keep the file path, and if an error occurs put that value back into the input box.

This wont be pretty, the input type for files is one of those special cases where the browser is responsible for a lot of the user interaction.

Remember in most cases what is happening is the browser is collection the byte information from the file and passing that around as part of the request, this is not something you are going to be able to manipulate easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜