不使用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.