文件输入和验证在ASP.NET MVC 2 [英] File input and validation in ASP.NET MVC 2

查看:114
本文介绍了文件输入和验证在ASP.NET MVC 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据seemse就像上传文件即使在ASP.NET MVC2。

一件棘手的事情

我把一对夫妇intput(类型文件)的窗体上并提交大公时,很好地映射到我的视图模型。的问题是,如果ModelStat.IsValid为假则我们将返回到相同的形式和fileinputs将是空

我知道,它可以清除输入字段(通过替换它),但我不明白我怎么能正确设置输入?

该用户必须能够看到/变更/甚至在服务faild验证后返回表单时删除该文件上传,我该如何处理呢?

BestRegards


解决方案

浏览器不会让你prepopulate文件输入元素。如果他们这么做,那么恶意的Web应用程序可以重新从站点访问者的硬盘驱动器到服务器上传随机文件。

一般来说,这是处理的方式是,该文件保存到临时位置的服务器上,并且当输入被校正和形式重新上传服务器可以与现有的临时文件中的新输入的数据相关联。

Hi,

It seemse like uploading of files is a tricky thing even in ASP.NET MVC2.

I have placed a couple of intput(type file) on my form and when submitting thay are mapped to my viewmodel nicely. The problem is that if the ModelStat.IsValid is false then we will be returned to the same form and the fileinputs will be empty?

I know that its possible to clear a input field(by replacing it) but I do not see how I could set the input properly?

The users have to be able to see/change/remove the file upload even when returning to the form after a faild validation on the service, How can I handle this?

BestRegards

解决方案

Browsers will not allow you to prepopulate file input elements. If they did, then malicious web applications could just start uploading random files from the site visitor's hard drive to the server.

Generally the way this is handled is that the file is saved to a temporary location on the server, and when the inputs are corrected and the form reuploaded the server can associate the new incoming data with the existing temporary file.

这篇关于文件输入和验证在ASP.NET MVC 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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