HttpPostedFileBase DataAnnotations - 限制文件类型上载

时间:2015-02-17 11:21:54

标签: c# model-view-controller data-annotations

有没有办法为属性添加文件类型验证。无论文件类型如何,都会显示我的错误。

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" />
}

0 个答案:

没有答案
相关问题