Asp.net MVC: upload multiple image files?

前端 未结 4 427
礼貌的吻别
礼貌的吻别 2020-12-08 05:19

is there a good example of how to upload multiple image files in asp.net mvc? I know we can use HttpPostedFileBase to upload one file. Is there a way to upload multiple file

4条回答
  •  清歌不尽
    2020-12-08 05:43

    Some of the basic bits required for file uploads

    Notice keyword: multiple in input element AND multipart in form element

    HTML Side

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

    Controller

    [HttpPost]
    public ActionResult MyUpload(IEnumerable myFiles)
    {
        foreach (var file in myFiles)
        {
            if (file != null && file.ContentLength > 0)
            {
                //handle files;
            }
        }
        return View();
    }
    

提交回复
热议问题