How to post an array of files in ASP.NET MVC 3?

前端 未结 2 830
孤城傲影
孤城傲影 2021-02-08 17:25

I would like to be able to post multiple files in one form. I would like to pass these files as an array of files. For example I would like to do this.



        
相关标签:
2条回答
  • 2021-02-08 18:13

    If you want to upload not only one file, you need to use enctype="multipart/form-data" in your form.

    @using (Html.BeginForm("", "Client", FormMethod.Post, new {enctype="multipart/form-data"}))
    

    And controller:

    [HttpPost]
    public ActionResult AddPart(IEnumerable<HttpPostedFileBase> files) 
    

    All other parts is ok.

    0 讨论(0)
  • 2021-02-08 18:13

    Well i got almost a same case. But that is for nested array of files.

    using IEnumerable as an array([ ]) solved my problem. [] s

    [HttpPost]
    public ActionResult AddPart(IEnumerable<HttpPostedFileBase>[] files)
    
    0 讨论(0)
提交回复
热议问题