不使用jQuery回传类型文件的输入客户端验证 [英] Client validation of INPUT of type FILE without postback using jQuery

查看:116
本文介绍了不使用jQuery回传类型文件的输入客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查客户端上的一个文件已被选中,可以提交表单前。

I want to check on the client side that a file has been selected before the form can be submitted.

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm("Upload", "Files", FormMethod.Post, new { enctype = "multipart/form-data" }))
        { 
            <input id="File" name="File" type="file" size="80" />
            <input type="submit" name="name" value="Upload" />    
        }

进行验证目前这种形式是做回发。这是怎么回事了?

Currently this form is doing postbacks for validation. What is going wrong?

推荐答案

键入文件的输入是一个安全敏感的控制,而不是通过DOM脚本化。想象击中页面,并且页面设置控制值以一个敏感文件的一个众所周知的位置,并自动提交表单。上一次这种控制是脚本化将是约1995年或1996年。这是互联网安全的一个很无聊的时间。

An input of type "file" is a security-sensitive control and is not scriptable through the DOM. Imagine hitting a page, and that page sets the value of the control to a well-known location of a sensitive file and automatically submitting the form. The last time this control was scriptable would be about 1995 or 1996. That was a very silly time for internet security.

这篇关于不使用jQuery回传类型文件的输入客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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