本文介绍了如何保持INPUT TYPE =文件字段值ASP.NET MVC验证失败后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在MVC应用程序,我做了一个简单的表格。它包含一个文件域让用户可以上传图片。这一切的伟大工程。

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.

问题是,如果提交表单验证失败的文件字段的内容会丢失(等领域仍然稀少,THX HtmlHelpers!)。 如何保持一个验证失败后填充文件字段?

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!

推荐答案

浏览器的设计,因为安全隐患这样的方式。这是不可能的设置文件输入框的值在HTML源或通过的JavaScript。否则,恶意脚本能偷一些私人文件,而无需用户的关注。

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.

有有趣的信息了解的主题。

这篇关于如何保持INPUT TYPE =文件字段值ASP.NET MVC验证失败后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:00