---
title: "mvc upload file with model - second parameter posted file is null"  
description: "mvc upload file with model - second parameter posted file is null"  
author: "Anonymous User"  
published: 2014-12-09  
updated: 2014-12-10  
canonical: https://www.mindstick.com/forum/12777/mvc-upload-file-with-model-second-parameter-posted-file-is-null  
category: "asp.net"  
tags: ["c#", "mvc4", "model"]  
reading_time: 2 minutes  

---

# mvc upload file with model - second parameter posted file is null

I have a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model) with 1 [string property](https://www.mindstick.com/forum/160244/how-to-use-stringlength-to-limit-the-length-of-a-string-property-in-a-model) which I [render](https://www.mindstick.com/interview/2205/why-we-need-a-separate-mobile-project-template-while-we-can-render-our-web-application-in-mobile-what-s-new-in-mvc-4-mobile-template) on a simple view.

the view looks like the following:

```
@using (Html.BeginForm("UploadFile","Home", FormMethod.Post, new {
encType="multipart/form-data" })){    @Html.TextBoxFor(m=> m.FirstName)    <br /><br
/>     <input type="file" name="fileUpload" /><br /><br />    <input type="submit" value="submit me" name="submitme" id="submitme" />}
```

[Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) is this:

```
[HttpPost]public ActionResult UploadFile(UploadFileModel model, HttpPostedFileBase file){   // DO Stuff   return View(model);}
```

Now, when I submit, the model DOES get populated but the [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) being HttpPostedFileBase is null. However when doing [Request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php).Files - it does seem to show there is a file in the Request being posted. How can I actually get the second parameter to bind?

## Replies

### Reply by Anonymous User

Why not add the uploaded files to your model like this:

```
public class UploadFileModel {    public UploadFileModel()    {        Files = new List<HttpPostedFileBase>();    }     public List<HttpPostedFileBase> Files { get; set; }    public string FirstName { get; set; }    // Rest of model details}
```

Then change your view to this:

```
@using (Html.BeginForm("UploadFile","Home", FormMethod.Post, new {
encType="multipart/form-data" })){    @Html.TextBoxFor(m=> m.FirstName)    <br /><br
/>     @Html.TextBoxFor(m=> m.Files.Files, new { type = "file", name = "Files"
})<br /><br />    <input type="submit" value="submit me" name="submitme" id="submitme" />}
```

Then your files will be posted back as follows:

```
public ActionResult UploadFile(UploadFileModel model){    var file =model.Files[0];    return View(model);}
```


---

Original Source: https://www.mindstick.com/forum/12777/mvc-upload-file-with-model-second-parameter-posted-file-is-null

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
