Upload multiple files in one form MVC4

后端 未结 3 991
南笙
南笙 2021-02-04 13:42

I\'m trying to upload multiple images on one form

@using (Html.BeginForm(\"Create\", \"AdminRestaurants\", FormMethod.Post, new { enctype = \"multipart/form-data         


        
3条回答
  •  别那么骄傲
    2021-02-04 14:06

    This would only work if your file inputs had indexed names like files[0], files[1], files[2],...

    In order to understand how model binding to a list works in asp.net mvc, I recommend that you read this post: Model Binding to a List

    You don't even have to use model binding to get the files. Use Request.Files in your Action to get them.

    public ActionResult Create(EventsModel collection)
    {
        var files = Request.Files;
        // rest of the code...
    }
    

提交回复
热议问题