用法和定义:
enctype 属性规定在将表单数据发送到服务器之前如何对其进行编码。
默认是对表单数据以 "application/x-www-form-urlencoded" 进行编码。这意味着在发送前对所有字符进行编码(把 "+" 转换为空格,把特殊字符转换为 ASCII 十六进制值)。
属性值
值 | 描述 |
---|---|
application/x-www-form-urlencoded | 在发送前对所有字符进行编码(默认)。 |
multipart/form-data | 不对字符编码。当使用有文件上传控件的表单时,该值是必需的。 |
text/plain | 将空格转换为 "+" 符号,但不编码特殊字符。 |
在ASP NET MVC 3中可以这样使用
@using (Html.BeginForm("actionName", "ControllerName", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" id="ImgFile" name="ImgFile" />
}