我如何preserve选择跨请求的文件类型输入文件? [英] How do I preserve the file selected for a file type input across a request?

查看:98
本文介绍了我如何preserve选择跨请求的文件类型输入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 INPUT TYPE =一些意见文件标记。当我提交表单,如果有一个验证的问题,我的控制器动作返回相同/视图模型,但与验证错误,所选的文件输入文件被清除。我怎样才能preserve这个选择的文件?

I have an input type="file" tag in some views. When I submit the form, if there is a validation problem and my controller action returns the same/view model but with validation errors, the file selected for the file input is cleared. How can I preserve this selected file?

推荐答案

您通常会得到与 INPUT TYPE =密码标记相同的行为。它是用来帮助保护用户免受恶意服务器,谁可能试图通过pre-填充它们在一个文件上传字段来访问用户的私人敏感文件浏览器的一种安全措施。

You usually get the same behavior with input type="password" tags. It is a security measure in browsers used to help protect users from malicious servers, who might try to gain access to a user's private sensitive files by pre-populating them in a file upload field.

如果该文件是无效的,你为什么会想preserve呢?

If the file is invalid, why would you want to preserve it?

回复评论

如果是这样的话,你应该能够处理客户端上的其他字段验证没有做一个完整的回发。这将preserve用户的文件上传记录,因为页面就不会被发现被验证错误后,服务器重新呈现。

If that is the case, you should be able to handle the other field validations on the client without doing a full postback. This would preserve the users' file upload entry since the page would not be re-rendered by the server after validation errors are discovered.

这篇关于我如何preserve选择跨请求的文件类型输入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆