I\'m growing thin learving mvc3. I have the following code in my controller
[HttpPost]
public ActionResult Accreditation(Accreditation accreditation)
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)
{
...
}
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.
Checking this link will the fastest way for you to move on.
MVC 3 file upload and model binding
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.