File input and validation in ASP.NET MVC 2

折月煮酒 提交于 2019-12-11 05:21:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4844797/file-input-and-validation-in-asp-net-mvc-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!