有没有办法为属性添加文件类型验证。无论文件类型如何,都会显示我的错误。
public class XmlFile
{
[Required,
DataType(DataType.Upload),
FileExtensions(ErrorMessage = "Please specify a valid .xml file", Extensions = ".xml")]
public HttpPostedFileBase UploadedFile { get; set; }
}
我的观点:
@using (Html.BeginForm("Index", "Fatca", FormMethod.Post, new {enctype = "multipart/form-data"}))
{
<legend class="form-legend">Upload</legend>
<input type="file" name="UploadedFile"/>
<input type="submit" value="Upload" />
}