Uploading files with MVC 3

后端 未结 3 1156
走了就别回头了
走了就别回头了 2021-01-15 01:23

I\'m growing thin learving mvc3. I have the following code in my controller

    [HttpPost]
    public ActionResult Accreditation(Accreditation accreditation)         


        
相关标签:
3条回答
  • 2021-01-15 01:57

    Get your posted file directly in action:

    Here is discussion on SO: MVC 3 file upload and model binding

    [HttpPost]
    public ActionResult Accreditation(Accreditation accreditation, HttpPostedFileBase Passport)
    {
        ...
    }
    
    0 讨论(0)
  • 2021-01-15 02:01

    Are really uploading data? I'd suggest you use this way. Create a parameter of type HttpPostedFileBase with the same name as the input field and test for its content length property.

    Don't forget to use the same name for the parameter and for the input tag.

    Checking this link will the fastest way for you to move on.

    MVC 3 file upload and model binding

    0 讨论(0)
  • 2021-01-15 02:16

    var fileUpload = Request.Files[0]; is the line where you have your exception, isn't it? You should expect the file to be stored in the property of class Accreditation, not in Request.Files.

    So you need properties PressCard and Passport in Accreditation, both of type HttpPostedFileBase, and then use these properties in your code.

    0 讨论(0)
提交回复
热议问题