ASP.NET MVC3 RAZOR: File Upload gives zero as file count

后端 未结 2 2004
庸人自扰
庸人自扰 2020-12-20 05:04

I need to upload multiple files into web server using MVC3 with RAZOR. I have the following code. In the controller, I am getting zero as the file count. How to correct it t

相关标签:
2条回答
  • 2020-12-20 05:48

    change your form to match the following

    @using(Html.BeginForm("action","controller",FormMethod.Post,new{encType = "multipart/form-data"})){
    {
    
    <input type="file" name="files[0]" id="file1" />
    <input type="file" name="files[1]" id="file2" />
    <input type="file" name="files[2]" id="file3" />
    
    <input type="submit"  />
    
    }
    

    indices 0,1,2 will allow modelbinder to bind to IEnumerable furthermore encType also has to be specified when posting files to the server

    0 讨论(0)
  • 2020-12-20 05:48

    You must include the enctype attribute in the form tag to indicate that the form should include files.

    @using (Html.BeginForm("YourAction", "Controller", FormMethod.Post, new {enctype="multipart/form-data"))
    {
    }
    
    0 讨论(0)
提交回复
热议问题