如何上传和保存多个文件

时间:2014-12-14 10:42:25

标签: c# asp.net-mvc

我遇到文件上传控制问题。我有一个类如下:

public class EmployeeSuperClass
{
    //some other classes
    public DocumentsList AdditionalDocumentDetailsFields { get; set; }
}

public class EmployeeDocumentsTable
{
    public int EmployeeDocumentId { get; set; }
    public int EmployeeId { get; set; }
    public bool EmployeeDocumentIsMandatory { get; set; }
    public bool IsActive { get; set; }
    public string EmployeeDocumentName { get; set; }
    public string EmployeeDocumentDescription { get; set; }
    [RegularExpression(@"^.*\.(jpg|JPG|jpeg|JPEG|png|PNG|pdf|PDF)$", ErrorMessage = "Please use an image with an extension of .jpg, .png, .pdf")]
    public HttpPostedFileBase EmployeeDocumentFileName { get; set; }

    [Required]
    public string FilePath { get; set; }
}

使用这个类我要添加多个文档,因为一个员工在加入组织时可能会生成多个文档,所以我创建了以下文档列表:

public class DocumentsList
{
    public List<EmployeeDocumentsTable> documentsList { get; set; }
    public DocumentsList()
    {
        documentsList = new List<EmployeeDocumentsTable>();
    }
}

我想向员工添加多个文档。 任何人都可以想一想如何使用添加按钮添加多个文档,并在向员工添加多个文件后,我想一次保存所有文件?

1 个答案:

答案 0 :(得分:0)

我认为,如果您在文件上传控件中添加multiple="multiple",则会在上传时支持多项选择。您还应该显示控制器和视图以便更清晰。还要尝试显示您尝试过的内容以及失败的位置。您可以参考以下链接了解多个文件上传方案:

Multiple File Upload 1

Multiple File Upload 2

相关问题